in reply to Re^3: Protection from zombies
in thread Protection from zombies
This is equivalent to the Perl code I wrote in the original post. As strace shows, the parent gets stuck in the read call even if the child closes its stdout. Adding a write of 512 bytes to stdout to the child before it closes it makes the read in the parent return and everything works correctly. But that leaves me with the same question: how can the parent not get stuck in its read if I can't control what the child does?#include <sys/types.h> #include <sys/wait.h> #include <unistd.h> static char buf[512]; int main() { int pfd[2]; pipe( pfd ); pid_t pid = fork(); if ( pid ) { /* parent */ ssize_t s = read( pfd[0], buf, sizeof(buf) ); waitpid( pid, NULL, 0 ); } else { /* child */ dup2( pfd[1], STDOUT_FILENO ); close( STDOUT_FILENO ); } return 0; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Protection from zombies
by nomis80 (Sexton) on May 17, 2005 at 12:50 UTC | |
by kscaldef (Pilgrim) on May 17, 2005 at 17:51 UTC |