If I send a SIGTERM
signal to a process using the kill
command, I expect an exit code, but I always get 0 (zero) when running the below command after killing a process:
echo $?
According to the answer in this post, I should get 143 when sending a SIGTERM
to a process: Always app Java end with "Exit 143" Ubuntu
But I don´t get that exit code. Why?
To display the exit code for the last command you ran on the command line, use the following command: $ echo $? The displayed response contains no pomp or circumstance. It's simply a number.
137 = killed by SIGKILL Exit code 137 is Linux-specific and means that your process was killed by a signal, namely SIGKILL . The main reason for a process getting killed by SIGKILL on Linux (unless you do it yourself) is running out of memory.
RETURN VALUESIf successful, kill() returns a value of zero. On failure, it returns a value of -1, does not send a signal, and sets errno to one of the following values: EINVAL.
The exit code you get is for the kill
command itself. 0 means it succeeded, i.e. the other process got the signal you sent it. kill
just doesn't report the exit status for the process, since it can't even be sure the other process exited as a result of the signal it sent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With