Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- void child(int p[2]) {
- int value[1] = {0};
- while (*value < 9) {
- read(p[0], value, sizeof (int));
- printf(" < < < %d\n", *value);
- *value += 1;
- write(p[1], value, sizeof (int));
- sleep(1);
- }
- close(p[1]);
- close(p[0]);
- exit(EXIT_SUCCESS);
- }
- int main(void) {
- int pp[2];
- pipe(pp);
- if (fork() == 0) { child(pp); } // child() exits
- int value[1] = {0};
- while (*value < 9) {
- printf("%d > > > ", *value);
- fflush(stdout);
- *value += 1;
- write(pp[1], value, sizeof (int));
- sleep(1);
- read(pp[0], value, sizeof (int));
- }
- close(pp[0]);
- close(pp[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement