The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
catching some errors bebop1111116 Shell Programming and Scripting 5 09-29-2006 02:12 PM
Catching all Exit Codes Sivaswami J Shell Programming and Scripting 3 02-16-2006 07:13 PM
Awk- catching the last two chars Gerry405 UNIX for Dummies Questions & Answers 9 11-22-2005 06:23 AM
Catching signal and piping joseph_ng High Level Programming 7 11-14-2005 11:04 AM
catching interrupts toughguy2handle UNIX for Dummies Questions & Answers 1 09-19-2005 04:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-06-2004
xtrix xtrix is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 8
catching all signals in a single handler

Hi guys - got some questions... hope something helpfull will come out!!! I just want to catch every signal that can be caught and print some info by using only one handler.

I use the sigaction() function and only one instance of a sigaction struct as an argument to the sigaction() function.

1) If sigset_t sigaction.sa_mask is empty, things seem to work fine when i send signals to my process from the command line. However the shell sends an additional SIGCONT to my process for every signal that i send. Why is this happening?

2) If sigset_t sigaction.sa_mask is filled (meaning - from my point of view - that all signals should block while sig_handler's body is being executed) i get weird results. For example the scheduler (pid=0) is repeatedly sending a SIGBUS signal to my process. Why is this happening?

Thanx in advance, please have a look at the code...

P.S. This is a simplified version of the source code. In fact the program is multi-threaded. Anyway considering just one thread of execution, would this be right?

//----------------------------------------------------------------------------------
void sig_handler(int sig, siginfo_t * info, void * context)
{
FILE *f= fopen("signal_trap", "a");

if (sig == SIGILL || sig == SIGFPE || sig == SIGSEGV || sig == SIGBUS || sig == SIGCHLD || sig == SIGTRAP || sig == SIGPOLL)
fprintf(f, "Signal = %d, subcode = %d, pid = %d, uid = %d, address = %p, errno = %d\n", sig, info->si_code, info->si_pid, info->si_uid, info->si_addr, info->si_errno);
else
fprintf(f, "Signal = %d, pid = %d, uid = %d, address = %p, errno = %d\n", sig, info->si_pid, info->si_uid, info->si_addr, info->si_errno);

fprintf(f, "\n");
fclose(f);
}
//----------------------------------------------------------------------------------
int main()
{
struct sigaction act;
sigemptyset(&act.sa_mask); // or sigfillset(&act.sa_mask);
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = sig_handler;

sigaction(SIGABRT, &act, 0);
sigaction(SIGALRM, &act, 0);
sigaction(SIGFPE, &act, 0);
sigaction(SIGHUP, &act, 0);
sigaction(SIGILL, &act, 0);
sigaction(SIGINT, &act, 0);
sigaction(SIGPIPE, &act, 0);

// blah blah blah - all available signals use struct sigaction act

return 0;
}
//----------------------------------------------------------------------------------
  #2 (permalink)  
Old 12-06-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,126
When you a signal from pid 0, that is the kernel. It is sending a SIGBUS because your program has a bus error.
  #3 (permalink)  
Old 12-07-2004
xtrix xtrix is offline
Registered User
  
 

Join Date: Oct 2004
Posts: 8
not a very helpful answer.... what i am trying to find out is how sigemptyset and sigfillset affect sigaction when a single handler is used to catch all catchable signals. a process with pid = 0 is the sceduler or swapper, the father of all unix processes, which - of course - is part of the kernel. SIGBUS signals denote access to an undefined portion of a memory object and not bus errors...
  #4 (permalink)  
Old 12-09-2004
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,777
FWIW - SIGBUS is not precsiely what you described - you basically described SIGSEGV.

What Perderabo is telling you, politely, is that you have code errors.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0