Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #define BUFSIZE 256
- main()
- {
- int c1p[2]; //pipe to link c1 to c2
- int c1pid; //parent ID
- int c1status;
- int c2p[2]; //pipe
- int c2pid; //parent ID
- int c2status;
- int c3p[2]; //pipe
- int c3pid; //parent ID
- int c3status;
- int len;
- char buffer[BUFSIZE];
- int read_len;
- pipe(c1p);
- c1pid = fork();
- if (c1pid == 0) {
- int newfd = 1;
- newfd = dup2(c1p[1],newfd);
- if (newfd != 1)
- {
- fprintf(stderr,"unable to duplicate newfd \n");
- exit(1);
- }
- close(c1p[0]);
- execvp("./c1", NULL);
- } else {
- c1pid = wait(&c2status);
- printf("process 2 finished \n");
- }
- pipe(c2p);
- c2pid = fork();
- if (c2pid == 0) {
- int newfd = 1;
- newfd = dup2(c2p[1],newfd);
- if (newfd != 1)
- {
- fprintf(stderr,"unable to duplicate newfd \n");
- exit(1);
- }
- close(c2p[0]);
- execvp("./c2", NULL);
- } else {
- c2pid = wait(&c2status);
- printf("process 2 finished \n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement