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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 02:33:01  来源:igfitidea点击:

Linux: get the exit code from the kill command

linuxkillexit-codesigterm

提问by Rox

If I send a SIGTERMsignal to a process using the killcommand, 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 SIGTERMto 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 killcommand itself. 0 means it succeeded, i.e. the other process got the signal you sent it. killjust 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只是不报告进程的退出状态,因为它甚至不能确定另一个进程由于它发送的信号而退出。