From a shell, say Bash, is it possible to retrieve the signal number received by the application that most recently finished, if any, in a way that is similar to checking the return code of a process by printing $?
.
Asked
Active
Viewed 967 times
4
-
2Possible duplicate of Linux signals logger – JigglyNaga Nov 28 '18 at 14:47
1 Answers
3
When a process is killed, the signal that killed it is encoded in the exit status retrieved by the parent (or child subreaper or init
for orphans).
In bash
, $?
is 128+signum.
That's what most Bourne-like shells do, ksh93 uses 256+signum, yash 384+signum.
$?
being 129
in bash
either means the process was killed by signal 1 (SIGHUP) or that it did a exit(129)
. If it did a exit(129)
however, most likely that was to report a death by SIGHUP of some process.
To get the signal name from the value of $?
, run:
kill -l "$?"
That works in all Bourne-like shells whether they use 128/256/384 + signum.
See details at Default exit code when process is terminated?

Stéphane Chazelas
- 544,893