How do I get EOF from a pipe I created?

Richard Tobin richard at aiai.ed.ac.uk
Tue Aug 7 23:42:43 AEST 1990


In article <6366.26be9bd9 at csv.viccol.edu.au> timcc at csv.viccol.edu.au (Tim Cook) writes:

>   if (fork ()) {
>      /* Subprocess */

No, fork() returns non-zero in the parent, so you're having the parent
rather than the child exec /dir/command.  This is why you are
returning to the shell and leaving the other process in the
background.  Try

    if(fork() == 0)

instead.

The other problem is that the process reading the pipe doesn't close the
other (write) end.  Read from a pipe returns eof if there is no process
that could write more data.  The parent should do this after the fork():

    close(pipe_descriptors[1]);

-- Richard
-- 
Richard Tobin,                       JANET: R.Tobin at uk.ac.ed             
AI Applications Institute,           ARPA:  R.Tobin%uk.ac.ed at nsfnet-relay.ac.uk
Edinburgh University.                UUCP:  ...!ukc!ed.ac.uk!R.Tobin



More information about the Comp.unix.wizards mailing list