previous | start | next

Process Group Example - version 3

    1   
    2   pid_t cpid;
    3   
    4   void sigint_handler(int sig)
    5   {
    6     printf("pid %d got SIGINT, ", getpid()); 
    7     if (cpid != 0 ) {
    8       printf("sent SIGINT to child %d, then ", cpid);
    9       kill(cpid, SIGINT);
   10     }
   11     printf("exited\n");
   12     exit(0);
   13   }
   14   
   15   
   16   int main()
   17   {
   18   
   19     Signal(SIGINT, sigint_handler);
   20     if ( (cpid = fork()) == 0 ) {
   21       setpgid(0,0);
   22       printf("child pid = %d, gid = %d\n", getpid(), getpgrp());
   23       pause();
   24     }
   25   
   26     printf("parent pid = %d, gid = %d\n", getpid(), getpgrp());
   27     pause();
   28   
   29     return 0;
   30   }


previous | start | next