如何确定进程被杀死? (使用kill命令)
我尝试在Linux中使用kill命令来终止一个进程。 (不使用 -9 作为参数)
我需要确保该进程确实被终止。 据我所知,kill 命令异步运行,可能需要一些时间才能完成。
我需要确保在使用 bash 运行kill 后我的进程已终止,
您可以帮忙吗?
谢谢!!!
I try to kill a process with the kill command in linux. (not using -9 as argument)
I need to make sure that the process is really killed.
As far as I know, the kill command runs asynchronously and it can take some time till it is finished.
I need to make sure, after I run the kill that my process has died using bash
Can you please assist?
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设
$PID
保存着你的进程的 pid,你可以这样做:Assuming
$PID
holds the pid of your process, you could do something like this:使用信号 0 杀死进程将检查该进程是否仍在运行,而不是实际杀死它。只需检查返回码即可。
Killing a process with signal 0 will check if the process is still running, and not actually kill it. Just check the return code.
kill
用于向进程发送信号。它不一定会终止该进程(但通常会终止)。如果没有明确提及的kill
信号,则会向进程发送SIGTERM
。SIGTERM
上的默认操作是终止进程,但进程可以设置不同的信号处理程序,并且进程可能不会终止。我认为您需要的是一种查找进程是否已处理信号的方法。这可以使用 ps s $PID 来完成。如果这显示
0
s 作为待处理掩码,则进程已收到信号并对其进行处理。kill
is used to send signals to processes. It doesn't necessarily terminate the process (but usually do).kill
without explicitly mentioned signal will sendSIGTERM
to the process. The default action onSIGTERM
is to terminate process but process can setup a different signal handler and process might not be terminated.What, I think you need, is a way to find if the process has handled the signal or not. This can be done using
ps s $PID
. If this shows0
s as pending mask, the process has received the signal and processed it.