This is test6.c in view mode; [Download] [Up]
/* * FILE: A test of the sigwait() service. * * Creates a single sigwaiter to wait for a SIGINT, SIGTERM, SIGHUP, * or SIGQUIT signals. */ #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <utils.h> #define THREADS ((int) 4) extern int getpid( void ); void waiter( void ) { sigset_t sigset; int caught = FAILURE; sigemptyset( &sigset ); sigaddset( &sigset, SIGINT ); sigaddset( &sigset, SIGTERM ); sigaddset( &sigset, SIGHUP ); sigaddset( &sigset, SIGQUIT ); pthread_sigmask( SIG_SETMASK, &sigset, NULL ); switch((caught = sigwait( sigset ))) { case SIGINT: printf("Caught SIGINT"); break; case SIGTERM: printf("Caught SIGTERM"); break; case SIGHUP: printf("Caught SIGHUP"); break; case SIGQUIT: printf("Caught SIGQUIT"); break; default: printf("Error: %d\n", caught ); break; } pthread_exit( (void *) caught ); } static pthread_t th;; int main( int argc, char *argv[] ) { int exit_status, st; printf("pid %d: Blocked %d %d %d %d\n", getpid(), SIGINT, SIGQUIT, SIGHUP, SIGTERM ); create_joinable( &th, (thread_proc_t) waiter, NULL ); st = pthread_join( th, (void **) &exit_status ); CHECK( st, "pthread_join()"); return( EXIT_SUCCESS ); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.