capturing synchronous signals


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users capturing synchronous signals
# 1  
Old 04-22-2009
capturing synchronous signals

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;
}
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help with Signals

Hi All, The problem statement is as below: Problem: A process (exe) is getting executed in background. The output of this process is getting logged in a file. After successfully running for some time the process gets terminated. In the log file following is present: ^M[7m Interrupt ^M[27m... (8 Replies)
Discussion started by: Praty.27
8 Replies

2. UNIX for Dummies Questions & Answers

pending signals

I was wondering about following. If I have set of 3 signals. And they are all blocked.Now at some point in the program the set is unblocked. Which signal will be delivered first.This is my set....SIGTSTP,SIGQUIT,SIGINT.When I added them in the set and unblock them I did it in following order... ... (1 Reply)
Discussion started by: joker40
1 Replies

3. UNIX for Dummies Questions & Answers

Blocking signals

I know how to add signal to a set. But what if I want to add 2 or 3 signals to the set. I know I can use sigaddset (&set,SIGBUS)....but what if I want to add SIGBUS and SIGALRM at once. Do i have to do it like this.. sigaddset (&set,SIGBUS); sigaddset (&set,SIGALRM); Is there another way to... (0 Replies)
Discussion started by: joker40
0 Replies

4. UNIX for Dummies Questions & Answers

perror with signals

I have following problem with this code.. First time trough the main loop..... perror gives ....blocked signal:success(all other times gives illlegal seek) Should every time trought the main loop be success?? And the perror otside of main loop...didn't change mask:success That line of code... (2 Replies)
Discussion started by: joker40
2 Replies

5. UNIX for Dummies Questions & Answers

Help understanding signals

I am having trouble with folowing sigset_t s; // now s represents set of signals sigemptyset(&s) ; // initialize this set and exclude all the signals from it.is it empty? sigaddset(&s,SIGILL);//this set containts only SIGILL signal sigprocmask(SIG_BLOCK,&s,NULL);//lost on this one Can... (3 Replies)
Discussion started by: joker40
3 Replies

6. Programming

Using Signals

How can use signals in a C program If i want a child program to signal it's parent program that it(child) program has completed the task that it was assigned.:confused: (2 Replies)
Discussion started by: kapilv
2 Replies

7. UNIX for Dummies Questions & Answers

Signals...

(posted this in the scripting forum as well, but figured it should go here) So, what's going on is this: For our program, we had to create our own shell, and if the user pressed ctrl-c just at the cmdline, then this signal would be ignored, but if there is a foreground process running, let's... (0 Replies)
Discussion started by: blind melon
0 Replies

8. HP-UX

Threads and Signals

I want to handle signals in a process that involves lots of threads. Now I do know that there should be a dedicated thread that will actually be traping signals and then these signals will be ditributed to actual threads. My question is...in case a signals has been generated by a kernel for the... (0 Replies)
Discussion started by: ripunjay
0 Replies

9. Programming

Signals In HP-UX

does the way of handling, interrupting signals in HP-UX same as that of solaris. If there is difference than what it is.?:confused: (1 Reply)
Discussion started by: kapilv
1 Replies
Login or Register to Ask a Question