Skip to content

Commit 86f96f5

Browse files
author
Margo
committed
Cleanup
1 parent c9c92fe commit 86f96f5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

shell3/pipe1.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
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.
1011
int 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);

shell3/pipe2.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
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
1210
int main(int argc, char *argv[]) {
1311
(void)argc;
1412
(void)argv;

0 commit comments

Comments
 (0)