Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux: how to see if a living process has signal handlers set?

Tags:

linux

signals

There is a process happy running and I wonder if it has set some signal handlers. I recall I have once read something about this somewhere but could not find such information. Is it possible?

Thanks

like image 547
X.M. Avatar asked May 12 '11 08:05

X.M.


People also ask

Where are signal handlers executed?

Signal handlers usually execute on the current stack of the process. This lets the signal handler return to the point that execution was interrupted in the process. This can be changed on a per-signal basis so that a signal handler executes on a special stack.

How does the Linux OS know if we have registered a signal or not?

Inside the main() function, the signal() function is used to register a handler (sig_handler()) for SIGINT signal. The while loop simulates an infinite delay. So, the program waits for SIGNIT signal infinitely. The signal handler 'sig_handler' prints a debug statement by checking if the desired signal is SIGINT or not.

How do I check signals in Linux?

Under Linux, you can find the PID of your process, then look at /proc/$PID/status . It contains lines describing which signals are blocked (SigBlk), ignored (SigIgn), or caught (SigCgt).

Do threads share signal handlers?

All threads in a process share the set of signal handlers set up by sigaction(2) and its variants. A thread in one process cannot send a signal to a specific thread in another process.


2 Answers

gotta love that - presumably these are actually the signal sets...

cat /proc/self/status | grep -i '^Sig'

SigQ:   0/31404
SigPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000803
SigCgt: 0000000180014664

would seem could make a utility to print those out - unless anyone know of one already?

hmmm - time to read some kernel code for procfs

from this excellent article:

http://kernel.org/doc/Documentation/filesystems/proc.txt

SigQ                        number of signals queued/max. number for queue
SigPnd                      bitmap of pending signals for the thread
ShdPnd                      bitmap of shared pending signals for the process
SigBlk                      bitmap of blocked signals
SigIgn                      bitmap of ignored signals
SigCgt                      bitmap of catched signals
like image 170
chaosless Avatar answered Oct 09 '22 07:10

chaosless


you can detect this while checking the /proc/PID/status file.

The SigCgt mask display the caught signals by your application. (see man 7 signal for sigmask explanations)

like image 40
Cédric Julien Avatar answered Oct 09 '22 06:10

Cédric Julien