/*
 * sigaction.c.1
 */
#include <pthread.h>
#include <stdio.h>
#include "utils.h"

extern int getpid( void );

void
handler( int sig )
{
	pthread_lock_global_np();
	printf("Caught %s[%d]!\n", sys_signame[sig], sig );
	pthread_unlock_global_np();
}


int main( int argc, char *argv[] )
{
   struct sigaction act;
   struct timespec ts = { 0, 50000 };
   int i, signo = NSIG;
   
   printf("pid %d\n", getpid());

   for(i = 1; i < NSIG; i++ )
   {
	   if( i == 9 )
		   continue;
	   act.sa_handler = handler;
	   sigemptyset( &act.sa_mask );
	   pthread_sigaction_np( i, &act, NULL );
   }

   while( signo-- > 0 )
   {
	   pthread_delay_np( &ts );
	   pthread_kill( NULL, signo );
   }

   print_str("success!");

   return(0);
}
