Linux:从 kill 命令中获取退出代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8256511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux: get the exit code from the kill command
提问by Rox
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:
如果我SIGTERM
使用该kill
命令向进程发送信号,我希望有一个退出代码,但在杀死进程后运行以下命令时,我总是得到 0(零):
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
根据这篇文章中的答案,我应该在向SIGTERM
进程发送时得到 143 :Always app Java end with "Exit 143" Ubuntu
But I don′t get that exit code. Why?
但我没有得到那个退出代码。为什么?
采纳答案by Fred Foo
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.
您获得的退出代码用于kill
命令本身。0 表示成功,即另一个进程收到了您发送的信号。kill
只是不报告进程的退出状态,因为它甚至不能确定另一个进程由于它发送的信号而退出。