Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux: get the exit code from the kill command

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?

like image 754
Rox Avatar asked Nov 24 '11 11:11

Rox


People also ask

How do I find exit code in Linux?

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.

What is the exit code of a killed process?

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.

What does kill command return?

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.


1 Answers

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.

like image 56
Fred Foo Avatar answered Sep 21 '22 09:09

Fred Foo