LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-22-2009, 06:33 AM   #1
sky rulz
Member
 
Registered: Jun 2008
Posts: 40

Rep: Reputation: 15
regarding asynchronous signal


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;
}
 
Old 04-22-2009, 08:45 AM   #2
rriggs
Member
 
Registered: Mar 2009
Location: Colorado, US
Distribution: Fedora 13, Fedora 14, RHEL6 Beta
Posts: 46

Rep: Reputation: 17
This should explain it for you: http://www.linuxjournal.com/article/3985
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to reinstall a signal handler after exec ( Strange behaviour in signal handling ) lali.p Programming 0 09-20-2008 12:11 PM
Signal frequency out of range / please change signal timing starrynite Linux - Hardware 1 01-06-2007 11:18 AM
Signal Strength Meter shows low signal? falcon56215 Linux - Networking 0 09-15-2006 07:39 AM
Signal 6: Unknown Signal <=> Error with MAYA4.X under Linux SOLVED!!!! Faeroon Linux - Software 9 05-09-2003 01:57 PM
Signal: 6 (Unknown Signal) - Problems running a program Faeroon Linux - Software 86 01-14-2003 12:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration