Open System Services Programmer's Guide
executed, and signal 8 (SIGFPE) is received by the thread. On successful return from a
signal-catching function for a SIGFPE, SIGILL, SIGLIMIT,SIGMEMERR, SIGMEMMGR, SIGNOMEM,
SIGSEGV, SIGABRT, or SIGSTK signal that was not generated by a kill() or raise() function
call, a process receives a SIGABEND signal and terminates.
Example 86 Handling the Synchronous Signal SIGFPE
/* This test program demonstrates handling the */
/* SIGFPE synchronous signal. */
#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 */
/*Define a signal handler for this thread */
void sighand(int signo);
int x=10,y=0,z;
void *threadfunc(void *parm)
/* Perform the illegal operation of dividing by zero and */
/* raise the SIGFPE signal. The SIGFPE signal is sent to */
/* the generic handler. */
{
signal(SIGFPE,sighand);
z = x/y;
my_printf("\nI am in thread1\n");
return NULL;
}
int main(int argc, char **argv)
{
pthread_t thread1;
my_printf("Enter Testcase - %s\n", argv[0]);
/* create the thread */
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);
}
Example 87 (page 391) creates a thread that waits for asynchronous signal SIGINT.
Sample input:
> kill -2 process-name
or
<CRTL-C>
Both of these inputs generate a SIGINT signal.
390 Using the POSIX User Thread (PUT) Model Library