This is test3.c in view mode; [Download] [Up]
/* * FILE: A test of pthread_sigaction() */ #include <pthread.h> #include <stdio.h> #include <utils.h> extern int getpid( void ); void ctrl_c_handler( int sig ) { printf("^C interrupt."); pthread_kill( NULL, SIGKILL ); } void term_handler( int sig ) { pthread_lock_global_np(); printf("Caught %d %s in handler!\n", sig, sys_signame[sig] ); pthread_unlock_global_np(); } void catcher( void ) { struct timespec ts = { 0, 50000 }; while( 1 ) { printf("catcher"); pthread_delay_np( &ts ); } pthread_exit( (void *) 0 ); } int main( int argc, char *argv[] ) { pthread_t th; struct sigaction act; struct timespec ts = { 0, 100000 }; act.sa_handler = term_handler; sigemptyset( &act.sa_mask ); pthread_sigaction_np( SIGTERM, &act, NULL ); act.sa_handler = ctrl_c_handler; sigemptyset( &act.sa_mask ); pthread_sigaction_np( SIGINT, &act, NULL ); pthread_create( &th, NULL, (thread_proc_t) catcher, NULL ); /* * Sleep for 0.5 seconds, wake-up, and send a signal to the * catcher thread. Do this until the process takes a kill -9. */ while( 1 ) { pthread_delay_np( &ts ); pthread_kill( th, SIGTERM ); } return(0); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.