Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <stdlib.h>
  6. #include <sys/wait.h>
  7.  
  8. int main(int argc, char **argv) {
  9. if (argc != 3) {
  10. return 1;
  11. }
  12. int pipes[2];
  13. if (pipe(pipes) == -1) {
  14. return 1;
  15. }
  16. int pid = fork();
  17. if (pid == -1) {
  18. exit(1);
  19. }
  20. if (!pid) {
  21. dup2(pipes[1], 1);
  22. close(pipes[0]);
  23. close(pipes[1]);
  24. execlp(argv[1], argv[1], NULL);
  25. _exit(1);
  26. }
  27. pid = fork();
  28. if (pid == -1) {
  29. exit(1);
  30. }
  31. if (!pid) {
  32. dup2(pipes[0], 0);
  33. close(pipes[0]);
  34. close(pipes[1]);
  35. execlp(argv[2], argv[2], NULL);
  36. _exit(1);
  37. }
  38. close(pipes[0]);
  39. close(pipes[1]);
  40. wait(NULL);
  41. wait(NULL);
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement