[英]Cannot kill pid 1 inside docker container with SIGKILL
For a reason, I want to kill the main python process ( PID 1 ) in docker container. 有一个原因,我想杀死docker容器中的主要python进程(PID 1)。 But non of the terminating signals such as
SIGTERM
, SIGKILL
work. 但是没有像
SIGTERM
, SIGKILL
那样的终止信号。 I mean, running kill -SIGKILL 1
has no effect. 我的意思是,运行
kill -SIGKILL 1
没有效果。 How can I kill the pid 1 from the inside of container ? 如何从容器内部杀死pid 1? I do not want to run
docker stop
or similar solutions. 我不想运行
docker stop
或类似的解决方案。
According to the Docker issue tracker and how the general documentation of pid 1s state, you need to specifically add a handler to the signals and kill the process from them. 根据Docker问题跟踪器以及pid 1s的一般文档说明,您需要专门为信号添加处理程序并从中杀死进程。
signal.signal(signal.SIGINT, exit_gracefully)
signal.signal(signal.SIGTERM, exit_gracefully)
exit_gracefully
needs to be defined and eventually call sys.exit(0)
. exit_gracefully
需要定义并最终调用sys.exit(0)
。
This behaviour is wanted and enforced by the kernel as it will not call the sigaction
default, which is is termination, on the other pids. 内核需要并强制执行此行为,因为它不会在其他pid上调用
sigaction
default(即终止)。
We need to do something similar in Node.js. 我们需要在Node.js中做类似的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.