Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //DAVID GARCÍA RUIZ
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- void main(int argc,char *argv[])
- {
- //funcion usage
- int p[2];
- int pid;
- pipe(p);
- int i;
- for(i = 2; i<argc; ++i){
- pid = fork();
- if (pid == 0){
- dup2(p[1],1);
- close(p[0]); close(p[1]);
- execlp("cat","cat",argv[i],(char *)0);
- perror("execlp");
- }
- else if(pid<0); // falta error
- else waitpid(pid, NULL, 0);
- }
- pid = fork();
- if (p == 0){ //GREP.
- close(p[0]);
- execlp("grep","grep", argv[1],(char *)0);
- perror("execlp");
- }
- close(p[0]);
- waitpid(pid,NULL,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment