catching all signals in a single handler


 
Thread Tools Search this Thread
Top Forums Programming catching all signals in a single handler
# 1  
Old 12-06-2004
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 Smilie - 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  
Old 12-06-2004
When you a signal from pid 0, that is the kernel. It is sending a SIGBUS because your program has a bus error.
# 3  
Old 12-07-2004
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  
Old 12-09-2004
FWIW - SIGBUS is not precsiely what you described - you basically described SIGSEGV.

What Perderabo is telling you, politely, is that you have code errors.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Catching error in sftp

Hi All Experts, I have a script which logs to the server via sftp connection with below code :- user_name@sftp_server.com and the connection is going smooth. My requirement is to place file in sftp_server in some path. and if path doesn't exist or the file is not put successfully I... (3 Replies)
Discussion started by: punitsoneji
3 Replies

2. Programming

SIGCHLD interrupts its own handler

Hi. I have a program whose job it is to manage 15 child processes. Sometimes these children die (sometimes deliberately other times with a SEGV). This causes a SIGCHLD to be sent to my program which uses waitpid() in the signal handler to gather information and, in most cases, restart the child.... (3 Replies)
Discussion started by: jrichemont
3 Replies

3. UNIX for Dummies Questions & Answers

Doubt with irq handler.......

Hello, I have develop a driver for my hardware and now, I need to handle a IRQ but I does not work. As I can understand, to handle a irq, it is necessary to make a request_irq(). If the return value is zero, ok, no problem to handle irq. Here is a easy example of my driver: #include... (8 Replies)
Discussion started by: webquinty
8 Replies

4. Shell Programming and Scripting

Catching errors

Hi, I'm writing a scheduling script which will co-ordinate the launching of scripts. This script is scheduling based on an input file, and launches the appropriate scripts at the right times. The only issue I'm having is: - if a script dies, or even has a syntax error, I want to catch... (1 Reply)
Discussion started by: GoldenEye4ever
1 Replies

5. Shell Programming and Scripting

XML Handler in perl

Hi there, I'm newby in perl and XML. I can read and parse Xml with XML-Node upper XML::Parser, but how can I create XML tags and pack my individual data in it then send through socket. PLZ lead me :) Meanwhile what is your opinion about XML Writer library? Thanks in Advance. (2 Replies)
Discussion started by: Zaxon
2 Replies

6. Programming

Signal catching

Hi! I want to catch all signals that my program receives print their name and then execute the default handler. Can you help me on that? I've tried the following code: #include <stdio.h> #include <unistd.h> #include <signal.h> void (*hnd)(int i); char signals = { "SIGHUP",... (7 Replies)
Discussion started by: dark_knight
7 Replies

7. UNIX for Dummies Questions & Answers

Catching print jobs.

Hi, I am wondering how to catch print jobs to process them before been served to the printer. I was told that the challenge is to catch raw text that an old legacy application sends to the printer (invoices, quotes, etc) and save them as text files to allow a new application to process them... (5 Replies)
Discussion started by: miguel77mex
5 Replies

8. Shell Programming and Scripting

catching some errors

I need to find a way to keep a running tally of how many times events or actions occur. Say if a user is prompted to make inputs of 1 or 2, I want it to keep track of how many times 1 was entered, and how many times 2 was entered. Thanks for your help (5 Replies)
Discussion started by: bebop1111116
5 Replies

9. UNIX for Dummies Questions & Answers

catching interrupts

hey i have been facing a problem,can you tell me if we can catch ctrl d in unix i have tried and sucessfully catched and disabled ctrl-c and ctrl -z but am not sure if we can do the same for CTRL-D, so got any clue mail on he forum or ...i mean c programming in Unix thats what i am working on (1 Reply)
Discussion started by: toughguy2handle
1 Replies
Login or Register to Ask a Question