Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1.     pid_t PPID = getpid();          //  Get PID of parent process
  2.     for (int i = 0; i < n; i++)
  3.     {
  4.         pid_t ppid = getppid();     //  Get PPID of current process running
  5.         if (ppid == PPID)           //  Sleep child
  6.         {
  7.             sleep(10);
  8.             exit(-1);
  9.         }
  10.  
  11.         pid_t new_pid = fork();
  12.         if (new_pid != 0)           // Print process id only in parent process
  13.             printf("# New child created, pid: %d, ppid: %d\n", new_pid, getppid());
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement