Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. void pipeusage(int writingEnd,int readingEnd,char* message)
  6. {
  7. pipefirst(writingEnd);
  8. }
  9.  
  10. void pipefirst(int writingEnd,char* message)
  11. {
  12.  
  13. }
  14.  
  15.  
  16. int main(int argc, char** argv)
  17. {
  18. if (argc==1)
  19. {
  20. if (!fcntl(68,F_GETFD)) return -1; //wypis peeror
  21. else lastchild();
  22. }
  23. int fd[2];
  24. if (pipe(fd)==-1) return -1;
  25. int id = fork();
  26. char** new_point = (char**)malloc(sizeof(char*)*(argc));
  27. for(int i=1; i<argc;++i) new_point[i-1]=argv[i];
  28. new_point[argc] = NULL;
  29. if (!id)
  30. {
  31. close(fd[1]);
  32. dup2(fd[0],68);
  33. close(fd[0]);
  34. execvp("./test_prog",new_point);
  35. }
  36. close(fd[0]);
  37. if (!fcntl(68,F_GETFD))
  38. {
  39. pipefirst(fd[1],argv[1]);
  40. }
  41. else
  42. {
  43. pipeusage(fd[1],68,argv[1]);
  44. }
  45. waitid(id);
  46. free(new_point);
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement