home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / c / pthd-0.000 / pthd-0 / pthd-0.7 / src_signals / sigaction.c.2 < prev    next >
Encoding:
Text File  |  1995-08-16  |  1.5 KB  |  62 lines

  1. /*
  2.  * sigaction.c.2
  3.  *
  4.  * Launch this program and then issue kill -<signo> <pid>.  I run through
  5.  * all of the signals from 1 - 31.  Signals 5 (SIGTRAP) and 9 (SIGKILL)
  6.  * terminate the process because they can not be handled.  Signal 26
  7.  * is ignored completely because the thread's runtime won't let any
  8.  * one mess with SIGVTALRM.  Signals #17 (SIGCHLD) and #18 (SIGCONT)
  9.  * are not delivered to the process.
  10.  *
  11.  * Also, try this one:  Start up the process then send it a SIGSTOP (#19).
  12.  * Next send it a SIGINT (#2).  Nothing should happen because the process
  13.  * is asleep.  Next, issue a SIGCONT (#18).  Notice that the SIGINT is
  14.  * delivered upon wakeup from the suspended state.  Just as it's supposed
  15.  * to be.
  16.  */
  17. #include <pthread.h>
  18. #include <stdio.h>
  19. #include "utils.h"
  20.  
  21. extern int getpid( void );
  22.  
  23. void
  24. handler( int sig )
  25. {
  26.     pthread_lock_global_np();
  27.     printf("Caught %d %s in handler!\n", sig, sys_signame[sig] );
  28.     pthread_unlock_global_np();
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34.    struct sigaction act;
  35.    struct timespec ts = { 1, 0 };
  36.    int i, nreps = 20;
  37.  
  38.    printf("pid %d: ", getpid()); fflush( NULL );
  39.    for(i = 1; i < NSIG; i++ )
  40.    {
  41.        act.sa_handler = handler;
  42.        act.sa_mask = (SA_RESTART);
  43.        sigemptyset( &act.sa_mask );
  44.        pthread_sigaction_np( i, &act, NULL );
  45.    }
  46.  
  47.    /*
  48.     * Sleep for 0.5 seconds, wake-up, then go back to sleep.  Do this
  49.     * 5 times or until the process takes a kill -9.
  50.     */
  51.    while( nreps > 0 )
  52.    {
  53.        pthread_delay_np( &ts );
  54.        nreps -= 1;
  55.        printf("."); fflush(NULL);
  56.    }
  57.  
  58.    printf("   done\n");
  59.  
  60.    return(0);
  61. }
  62.