davidelgeek

Untitled

Nov 25th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. //DAVID GARCÍA RUIZ
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4. #include <sys/wait.h>
  5.  
  6. void main(int argc,char *argv[])
  7.  
  8. {
  9. //funcion usage
  10. int p[2];
  11. int pid;
  12. pipe(p);
  13. int i;
  14. for(i = 2; i<argc; ++i){
  15.     pid = fork();
  16.     if (pid == 0){
  17.         dup2(p[1],1);
  18.         close(p[0]); close(p[1]);
  19.         execlp("cat","cat",argv[i],(char *)0);
  20.         perror("execlp");
  21.     }
  22.     else if(pid<0); // falta error
  23.     else waitpid(pid, NULL, 0);
  24. }
  25. pid = fork();  
  26. if (p == 0){ //GREP.
  27.     close(p[0]);
  28.     execlp("grep","grep", argv[1],(char *)0);
  29.     perror("execlp");
  30. }
  31.     close(p[0]);
  32. waitpid(pid,NULL,0);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment