home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / 3bconnect / terminate.c < prev   
Encoding:
C/C++ Source or Header  |  1988-05-08  |  512 b   |  29 lines

  1. #include <sys/signal.h>
  2.  
  3. #define GRACETIME 1
  4. /*
  5.  * terminate: log out the child shell. Sends SIGHUP, SIGTERM, SIGKILL
  6.  * until the child exits.
  7.  */
  8. terminate(child)
  9. {
  10.     int status;
  11.     if(child < 1) return(0);
  12.     kill(child, SIGHUP);
  13.     alarm(GRACETIME);
  14.     if(wait(&status) == -1) {
  15.         kill(child, SIGTERM);
  16.         alarm(GRACETIME);
  17.         if(wait(&status) == -1) {
  18.             kill(child, SIGKILL);
  19.             alarm(GRACETIME);
  20.             if(wait(&status) == -1) {
  21.                 printf("Cannot kill child pid %d\n", child);
  22.                 status = 0;
  23.             }
  24.         }
  25.     }
  26.     alarm(0);
  27. }
  28.  
  29.