-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How to generate zombie processes to test PID 1 problem. #128
Comments
You should start a container with sshd as PID1. SSH to the container and test your script. If PID1 dies then a container should clean itself up so you won't see the issue that way. Think of a long running daemon in a container that rugularly spawns children (which also spawn children of children). The PID1 issue can affect long running daemons with infinite resource growth (or to a defined limit for the container). |
Thanks for the question! As far as I know, you're correct that zombie processes won't ever prevent a container from being stopped (and won't somehow stick to the host). The important things to understand about zombie processes (at least as I understand them) are:
I'd always suggest to use a proper init system that reaps zombies, but I don't really see that as the main reason to use dumb-init. Rather, I think the signal behavior (which can actually prevent containers from responding appropriately to Ctrl-C and other attempts to stop them) is more important. This is talked about in some depth in the blog post about dumb-init (especially under "Trouble signaling PID 1"). To answer your questions directly,
You need to create orphaned zombie processes, which means a process needs to spawn a child and then exit without reaping it. Here's an example Python script and Dockerfile: FROM debian:stretch
RUN apt-get update && apt-get -y install dumb-init procps python3
COPY test.sh /root/
CMD ["/root/test.sh"]
#CMD ["dumb-init", "/root/test.sh"] #!/usr/bin/env python3
import os
import subprocess
pid = os.fork()
if pid == 0: # child
pid2 = os.fork()
if pid2 != 0: # parent
print('The zombie pid will be: {}'.format(pid2))
else: # parent
os.waitpid(pid, 0)
subprocess.check_call(('ps', 'xawuf')) If you're not using dumb-init, you'll see:
If you're using dumb-init, you'll see:
To my knowledge, this isn't something that can happen once the container exits. |
I defer to @chriskuehl answer as I am likely wrong. He knows more about the issue than I. |
@chriskuehl Thanks for the detailed response! I was able to get a better picture of the problem through testing out your example. I guess I was creating zombie processes but not successfully orphaning them with my script which is why I was not seeing them after. Thanks again for the help. |
Is there a way of generating zombie processes using pure Bash? I'd like to test this on my container but I don't have Python installed. I've tried several things but I'm not sure the processes I've spawned are in the right state. |
I would like to gain some insight into the docker zombie process. Is there a simple way to produce a zombie in a docker container to see if it is reaped or not?
I am trying to create a zombie process that will persist even after the container is closed (that's what I understand the problem is in any case) so I can prove that using dumb-init as my ENTRYPOINT will fix the problem. However I haven't been able to show that the zombie process I created will stay no matter how I terminate my container or no matter how i terminate the parent of the zombie process.
I'm running nvidia/cuda:7.5-devel for the base image and docker v1.12.3. I've created a zombie in my container by having this script run as PID 1 in my dockerfile via CMD:
I started my test by launching 2 containers, 1 with dumb init as PID 1 (which launches my script) and 1 with the script as PID 1.
I can see the zombies here
but when I try to kill the parents either outside of inside of the container, the zombies are reaped even in the container not running dumb-init.
I'm looking for a way to reproduce this PID1 problem so I can show that dumb-init is doing this job because so far I haven't been able to show that zombies will stick to the host OS after the containers are killed, on the contrary the zombie processes are immediately reaped when I kill their parent process even if the container is still running.
The text was updated successfully, but these errors were encountered: