]
] That's what I did yesterday. After the forks, I put a
] for (i=0; i<2; i++) {
] if ((wait(&status)==pid1) close(pipe_fd[0]);
] else close(pipe_fd[1]);
] }
]
After the two forks, the shell should close both ends of the pipe, before
going into the wait loop. So, your code should become
4. pipe(pipe_fd)
5. in child of first fork: close(pipe_fd[0]),...
6. in child of second fork: close(pipe_fd[1]),...
7. in parent: close(pipe_fd[0]);close(pipe_fd[1]);
8. for (i=0; i<2; i++) wait(&status);
Otherwise, you keep too many copies of the pipe filehandles open:
pipe_fd[0] is open in child 2 and in parent, should only be open in child 2.
pipe_fd[1] is open in child 1 and in parent, should only be open in child 1.
I think this will solve your problem. If not, you must review the kernel
implementation of the pipe and you must doublecheck if all filehandles for a
terminated process are properly closed by the kernel during the clean-up.
1)
] > since the first can still receive input when the last
] > died. But most of the time it doesn't matter, since when the last process
] > dies, the first will recieve a "broken pipe" signal for any output it
] > sends.
]
2)
] I thought that "broken pipe" was an error code set by kernel when
] it tries to write to a pipe that has no readers... Interesting... I'll
] take a look...
Funny, two ways to say the same thing, since you can summarise 1) and 2) as:
1) A process that writes to a closed pipe, gets a "broken pipe" signal (from
the kernel)
2) The kernel sets the "broken pipe" signal, when a process tries to write to
a pipe that has no readers (hence, is closed).
Kind regards,
Alex Wulms
--
Alex Wulms/XelaSoft - MSX of anders NIX - Linux 4 ever
See my homepage for info on the *** XSA *** format
http://www.inter.nl.net/users/A.P.Wulms
****
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/)
****