Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1.  debug();
  2.     int pipefd[2];
  3.     pid_t cpid1;
  4.     pid_t cpid2;
  5.     if (pipe(pipefd) == -1)
  6.     {
  7.         perror("pipe");
  8.         _exit(EXIT_FAILURE);
  9.     }
  10.  
  11.     cpid1 = fork();
  12.     if (cpid1 == 0)
  13.     {
  14.         close(1);
  15.         if(dup2(pipefd[1], 1) == -1) perror("dup2"); if(close(pipefd[1]) == -1) perror("close");
  16.         close(pipefd[0]);
  17.         if(execvp(node->pipe.parts[0]->command.program,node->pipe.parts[0]->command.argv)==0) perror("Error pipe");
  18.         close(pipefd[0]);
  19.         close(pipefd[1]);
  20.         }
  21.          
  22.    
  23.     else
  24.     {
  25.         cpid2 = fork();
  26.         if (cpid2 == 0)
  27.         {  
  28.             close(0);
  29.             if(dup2(pipefd[0], 0) == -1) perror("dup2"); if(close(pipefd[0]) == -1) perror("close");
  30.             close(pipefd[1]);
  31.             if(execvp(node->pipe.parts[1]->command.program,node->pipe.parts[1]->command.argv)==0) perror("Error pipe");
  32.             close(pipefd[0]);
  33.             close(pipefd[1]);
  34.         }
  35.  
  36.         else
  37.         {
  38.             exit(-1);
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement