File tree Expand file tree Collapse file tree 2 files changed +4
-4
lines changed Expand file tree Collapse file tree 2 files changed +4
-4
lines changed Original file line number Diff line number Diff line change 66#include <string.h>
77#include <unistd.h>
88
9- // In this one, we close the write end of the pipe in the child
9+ // In this one, we close the child's write descriptor, so it should exit
10+ // when the parent closes its write.
1011int main (int argc , char * argv []) {
1112 (void )argc ;
1213 (void )argv ;
@@ -34,6 +35,7 @@ int main(int argc, char *argv[]) {
3435 printf ("\n" );
3536 } else if (p > 0 ) {
3637 // Parent -- will be writer
38+ close (pipefd [0 ]);
3739 printf ("Parent(%d)\n" , mypid );
3840 char * buf = "Message from parent to child\n" ;
3941 ssize_t len = (ssize_t )strlen (buf );
Original file line number Diff line number Diff line change 66#include <string.h>
77#include <unistd.h>
88
9- // In this one, we close the write end of the pipe in the child
10- // In this one, we close the extra read end too AND we make the pipe
11- // connect stdout to stdin.
9+ // Proper pipe hygiene and connecting to stdin/stdout
1210int main (int argc , char * argv []) {
1311 (void )argc ;
1412 (void )argv ;
You can’t perform that action at this time.
0 commit comments