Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSIX signal behavior

If a process is currently stopped due to a SIGTRAP signal and it is sent a SIGSTOP signal via kill(), what would be the default behavior? Would the SIGSTOP be a pending signal that is delivered after the process continues again? Or will it just be discarded/ignored?

If the SIGSTOP is queued up, is there any way to remove it from the queue from outside of that process, such as in a tracing process?

like image 218
ayelder Avatar asked Aug 05 '11 19:08

ayelder


People also ask

What is POSIX signal handling?

POSIX Signal Handling In modern POSIX, the Ublock in each process has a signal table (recall the previous post), which conceptually is a set of [signal/action] pair. For each signal in the reserved set, there is a corresponding default action that is usually “ignore” or “terminate” (see details on man page).

Which POSIX signals Cannot be caught?

Certain POSIX signals do not go through the condition handling steps described above: SIGKILL and SIGSTOP cannot be caught or ignored; they always take effect. SIGCONT immediately begins all stopped threads in a process if SIG_DFL is set.

Can SIGTERM be caught?

The SIGTERM signal is sent to a process to request its termination. Unlike the SIGKILL signal, it can be caught and interpreted or ignored by the process.

What is the difference between signal and sigaction?

The signal() function does not (necessarily) block other signals from arriving while the current handler is executing; sigaction() can block other signals until the current handler returns. The signal() function (usually) resets the signal action back to SIG_DFL (default) for almost all signals.


1 Answers

From the signal(7) man page:

The signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

A simple test with an app stopped on a breakpoint and sending it a SIGSTOP shows gdb displaying some information when I hit 'next'. The signal was obviously delivered to the app. It cannot continue to be debugged until I send it a SIGCONT.

(gdb) next
Program received signal SIGSTOP, Stopped (signal).
fill (arr=0x7fffffffdff0, size=5) at tmp.cpp:28
(gdb) next
Program received signal SIGCONT, Continued.
fill (arr=0x7fffffffdff0, size=5) at tmp.cpp:28
(gdb) next
(gdb) 
like image 126
Stéphane Avatar answered Sep 30 '22 11:09

Stéphane