-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5c9247
commit afdda52
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include<stdio.h> | ||
#include<unistd.h> | ||
#include<stdlib.h> | ||
#include<sys/types.h> | ||
|
||
|
||
int main(void) { | ||
/*Page 537, W. Richard Stevens*/ | ||
int n; | ||
int fd[2]; | ||
pid_t pid; | ||
char line[1024]; | ||
|
||
if (pipe(fd) < 0) { | ||
printf("Cannot create pipe"); | ||
return -1; | ||
} | ||
|
||
if ((pid = fork()) < 0) { | ||
printf("we are in china!"); | ||
return -1; | ||
} else if (pid > 0) { | ||
/* parent */ | ||
close(fd[0]); // parent who does not want to listen/read | ||
printf("From parent...\n"); | ||
write(fd[1], "Kuthe hotas!\n", 13); | ||
} else { | ||
/* child */ | ||
close(fd[1]); | ||
n = read(fd[0], line, 1024); | ||
write(1, line, n); | ||
} | ||
|
||
return 0; | ||
} | ||
|