Hi, again, people.

> Unix uses the fork()/exec() approach.

        This was an important explanation, Alex. Thank you.

> If you think that spawning many processes for a pipe is a waste of resources 
> on low-end systems like MSX you should use the temporary file approach, just 
> like MSXDOS and MS-DOS do.

        Yeah, I could, but it's not the right way (and it's toooooooo
dirty...), since the pipe() system call exists in UZIX kernel.

        Last night I tried my first implementation of pipes in sash (UZIX
default shell). I tried only with one pipe.
        My algorithm is:

        1. put arguments from prompt into char *argv[]
        2. check for the pipe symbol ("|")
        3. if not found pipe symbol, run as a single executable file
        4. pipe(pipe_fd) (result: pipe_fd[0]=read, pipe_fd[1]=write)
        5. first fork:
            close(pipe_fd[0])
            close(1)
            dup2(pipe_fd[1], 1)
            argv = all arguments before the pipe symbol
            execute(argv[0])
        6. second fork:
            close(pipe_fd[1])
            close(0)
            dup2(pipe_fd[0], 0)
            argv = all arguments after the pipe symbol
            execute(argv[0])
        7. [wait for all processes to terminate? only last one?]
        7. return to prompt
        
        Well, it works for the cat/more pair. Doing a cat fudeba.txt |
more works. But it doesn't work for the ls/more pair. System hangs after
displaying the last file in directory (NOTE: system doesn't crash, just
all processes goes to sleep mode).
        Another question is: shouldn't shell wait for all processes to
terminate? Or just for the last process?

        By the way, the pipe() syscall implementation is (well, seems to
be) right, since 'man' works (and it uses a pipe to 'more' to display
manual pages).

        Thanks for any help,


Adriano Camargo Rodrigues da Cunha               ([EMAIL PROTECTED])
Engenharia de Computacao - UNICAMP   
http://www.adrpage.cjb.net           http://if.you.dont.like.msx.usuck.com

* Hard Disk Failure. Message: "Stacker Rides Again!" *


****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****

Reply via email to