hi,
i created 2 threads in which one thread is dedicated to capture signals and handle them.
i used the following functions:
sigfillset for filling the signal set to be blocked by other threads
sigwait for waiting on particular signals
pthread_sigmask to mask block the signals.
I blocked all the signals with other threads the dedicated thread had no blocks at all on signals.
But, the main problem is the dedicated thread is capturing only the asynchronous signals like SIGINT but the synchronous signals(like SIGFPE,SIGSEGV) are not captured.
Can some one help me out in capturing the synchronous signals also?
when a synchronous signal(SIGFPE) is generated the process is terminated. why?
here is the code for that:
#include <stdio.h>
#include <signal.h>
#include <pthread.h>
// protoypes
void* sig_handler(void *);
void PrintData();
// global variables
int sig_handled = -1;
// mutex variables
pthread_mutex_t sig_mutex = PTHREAD_MUTEX_INITIALIZER;
int main()
{
sigset_t maskall;
pthread_t sig_thread;
pthread_t temp_thread;
// blocking all the signals to main thread and to child threads too
sigfillset(&maskall);
pthread_sigmask(SIG_BLOCK,&maskall,NULL);
// creating the dedicated handler
pthread_create( &sig_thread,NULL,sig_handler,NULL);
pthread_create( &temp_thread,NULL,(void*)PrintData,NULL);
for(;
{
}
return 0;
}
void* sig_handler(void* arg)
{
sigset_t unmaskall;
int signal_captured;
// unblocking all the signal for this thread
sigfillset(&unmaskall);
// waiting for the signals to occur
sigwait( &unmaskall, &signal_captured);
switch( signal_captured)
{
case SIGINT:
printf("captured signal is SIGINT\n");
break;
case SIGFPE:
printf("captured signal is SIGFPE\n");
break;
default:
printf("no signal captured\n");
break;
}
return (void *)0;
}
void PrintData()
{
printf("this is temporary thread\n");
int i=1/0;
return;
}