Guest User

Untitled

a guest
Aug 14th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include<unistd.h>
  2. #include<fcntl.h>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<errno.h>
  6. int main()
  7. { int pid,p[2];
  8.     if(-1==pipe(p))
  9.     {printf("Eroare pipe");
  10.         exit(1);
  11.     }
  12.     if(-1==(pid=fork()))
  13.     {printf("Eroare la fork");
  14.         exit(2);
  15.     }
  16.     if(pid==0)
  17.     {dup2(p[1],1);
  18.         execlp("grep","grep","/bin/bash","/etc/passwd",NULL);
  19.         perror("Eroare la execlp");
  20.         exit(3);
  21.     }
  22.     if(pid!=0)
  23.     {
  24.         close(p[1]);
  25.         dup2(p[0],0);
  26.         execlp("cut","cut","-d,","-f1",NULL);
  27.         perror("Eroare la execlp");
  28.         exit(5);
  29.     }
  30.    
  31.     return 0;
  32. }
Add Comment
Please, Sign In to add comment