![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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; } //---------------------------------------------------------------------------------- |
|
||||
|
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...
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|