Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <sys/wait.h>
  5. #include <string.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9.  
  10. int main()
  11. {
  12.  
  13. pid_t pid;
  14. int p[2];
  15.  
  16. mkfifo("p",0600);
  17.  
  18. //mkfifo("q",0600);
  19.  
  20. p[1]=open("p+",O_WRONLY);
  21. p[0]=open("p+",O_WRONLY);
  22. //q=open("q+",O_WRONLY);
  23.  
  24. pid=fork();
  25.  
  26. if(pid==0) /// fiul
  27. {
  28. close(p[0]); /// inchidem capatul pe care-l vom folosi in tata la preluarea output-ului acestui copil
  29.  
  30.  
  31. dup(p[1]); /// pt a trimite output-ul propriu
  32.  
  33. execlp("cat","cat","prog.c",NULL);
  34.  
  35. close(p[1]); /// inchidem capatul de output
  36.  
  37. }
  38.  
  39. else /// tatal
  40. {
  41. close(p[1]); ///inchidem capatul de output
  42.  
  43. dup(p[0]); /// pt a prelua ce era in capatul de output
  44.  
  45. execlp("grep","grep","include>","prog.c",NULL);
  46.  
  47. close(p[0]);
  48.  
  49.  
  50.  
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement