File tree 2 files changed +4
-4
lines changed
2 files changed +4
-4
lines changed Original file line number Diff line number Diff line change 6
6
#include <string.h>
7
7
#include <unistd.h>
8
8
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.
10
11
int main (int argc , char * argv []) {
11
12
(void )argc ;
12
13
(void )argv ;
@@ -34,6 +35,7 @@ int main(int argc, char *argv[]) {
34
35
printf ("\n" );
35
36
} else if (p > 0 ) {
36
37
// Parent -- will be writer
38
+ close (pipefd [0 ]);
37
39
printf ("Parent(%d)\n" , mypid );
38
40
char * buf = "Message from parent to child\n" ;
39
41
ssize_t len = (ssize_t )strlen (buf );
Original file line number Diff line number Diff line change 6
6
#include <string.h>
7
7
#include <unistd.h>
8
8
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
12
10
int main (int argc , char * argv []) {
13
11
(void )argc ;
14
12
(void )argv ;
You can’t perform that action at this time.
0 commit comments