For a reason, I want to kill the main python process ( PID 1 ) in docker container. But non of the terminating signals such as SIGTERM
, SIGKILL
work. I mean, running kill -SIGKILL 1
has no effect. How can I kill the pid 1 from the inside of container ? I do not want to run docker stop
or similar solutions.
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.
signal.signal(signal.SIGINT, exit_gracefully)
signal.signal(signal.SIGTERM, exit_gracefully)
exit_gracefully
needs to be defined and eventually call 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.
We need to do something similar in Node.js.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.