Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/wait.h>
  6.  
  7. int main(int argc, char **argv[]) {
  8. pid_t process_1;
  9. pid_t process_2;
  10. int fisier;
  11. int pipe_1[2];
  12. int pipe_2[2];
  13.  
  14. if(-1 == pipe(pipe_1)) {
  15. perror("Eroare la pipe!");
  16. return -1;
  17. }
  18.  
  19. process_1 = fork();
  20.  
  21. if(-1 == process_1){
  22. perror("Eroare la fork!");
  23. return -2;
  24. }
  25. else
  26. if(process_1 != 0) {
  27.  
  28. if(-1 == pipe(pipe_2)) {
  29. perror("Eroare la pipe!");
  30. return -3;
  31. }
  32.  
  33. process_2 = fork();
  34.  
  35. if(process_2 == -1) {
  36. perror("Eroare la fork!");
  37. }
  38.  
  39. if(process_2 != 0) {
  40. wait(NULL);
  41. } else if(process_2 == 0) {
  42. execl("/bin/wc", "wc", "-l", "p3.c" , NULL);
  43. }
  44.  
  45. }
  46. if(process_1 == 0) {
  47. execl("/bin/wc", "wc", "-w", "p3.c" , NULL);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement