Open System Services Programmer's Guide

In Example 87 (page 391), the signal handler of thread1 is executed and thread1 no longer
waits for a signal. Sample output:
Enter Testcase - ./Test2
sigaction returned 0
Wait for threads to complete
Signal received is 2
sigsuspend returned -1
Main completed.
Example 87 Handling the Synchronous Signal SIGINT
/* Program that demonstrates behavior of Asynchronous */
/* signal SIGINT */
#define _PUT_MODEL_ /** enables thread aware behavior **/
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include myio.h /** contains my_printf which is process-blocking**/
void sighand(int signo);
struct sigaction sigact_t;
sigset_t waitset;
void *threadfunc(void *parm)
{
int rc1,rc2;
sigfillset( &waitset );
sigdelset( &waitset,SIGINT);
sigact_t.sa_handler = sighand;
rc1 = sigaction(SIGINT,&sigact_t,NULL);
my_printf("\nsigaction returned %d\n",rc1);
rc2=sigsuspend(&waitset);
my_printf("\nsigsuspend returned %d\n",rc2);
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread1;
my_printf("Enter Testcase - %s\n", argv[0]);
pthread_create(&thread1, NULL, threadfunc, NULL);
sleep(1);
my_printf("Wait for threads to complete\n");
pthread_join(thread1, NULL);
my_printf("Main completed\n");
return 0;
}
void sighand(int signo)
{
my_printf("Signal received is %d\n",signo);
}
Signals and Signal Handling 391