Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1.  int status;
  2.  
  3.     signal(SIGINT, SIG_DFL);
  4.     if (fork() == 0)
  5.     {
  6.         int status;
  7.         int pipet[2];
  8.         pid_t pid1;
  9.         pid_t pid2;
  10.  
  11.         if (pipe(pipet) == -1)
  12.             _exit(EXIT_FAILURE);
  13.         pid1 = fork();
  14.         if (pid1 == 0)
  15.         {
  16.             close(pipet[0]);
  17.             dup2(pipet[1], 1);
  18.             execvp(code);
  19.         }
  20.         if (pid1 > 0)
  21.         {
  22.  
  23.             close(pipet[1]);
  24.             dup2(pipet[0], 0);
  25.             execvp(code);
  26.         }
  27.         else
  28.         {
  29.             perror("Error");
  30.         }
  31.  
  32.         close(pipet[0]);
  33.         close(pipet[1]);
  34.         wait(&status);
  35.     }
  36.     signal(SIGINT, SIG_IGN);
  37.     wait(&status);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement