杀死一个进程会杀死其他进程
我编写了一个 shell 脚本,它在有限循环中执行以下步骤:
生成一个进程,并等待它完成。如果它没有在 40 秒内完成,我会执行:
kill -SIGTERM pid
我发现有时,即使通过执行kill -SIGTERM pid,进程也不会响应被杀死。在这种情况下,再等待 40 秒等待其自行终止后,我会执行:
kill -9 pid
大多数情况下这已经足够了,然后我将继续执行这些步骤的下一个迭代。
问题: 有时,在执行上述一组步骤时,我最终不仅得到了我打算杀死的进程,而且还得到了运行执行这些步骤循环的脚本的 shell。
问: 造成这种情况的原因是什么?
I have a shell script I wrote which does the following steps within a finite loop:
I spawn a process, and wait for it to finish. If it does not finish within 40 seconds, I execute:
kill -SIGTERM pid
I have found sometimes, even by doing the kill -SIGTERM pid, the process doesn't respond to being killed. In this case, after an additional 40 seconds of waiting for it to kill itself, I then execute:
kill -9 pid
Most times this is sufficient, and I move on to the next iteration of these steps.
THE PROBLEM:
Sometimes in doing the above set of steps, I end up having not only the process I intended to kill, killed, but also the shell running the script which executes the loop of these steps.
QUESTION: What causes this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有两种可能性:
1.) 您传递的是 shell 或脚本的 PID,而不是子进程
2.) 您的 shell/脚本只是正常退出,因为子进程死了,就没有什么可做的了。
Two possibilities:
1.) you're passing the PID of the shell or script instead of the child process
2.) your shell/script is simply exiting normally because with the child process dead there is nothing left to do.