Docker (Process Tree)

Gioacchino Lonardo
2 min readMar 30, 2018

--

We will look at details of process management in dockers, especially on the process tree:

Process tree

We will look at details of process management in dockers, especially on the process tree:
A container will remain in operation until the process of the command we passed to it is alive (it is running). If the process ends naturally its execution or because we killed us or etc. the container goes into stopped.

PID number 1 is reserved for the init process. In this figure we have the view from the host (physical machine) point of view. PID number 1 is /sbin/init (machine init system, e.g. ubuntu). Let’s imagine having three processes that are the children of PID 1 (but we can have more), for example the 2312 process is associated with the user/bin/docker, that is the docker engine. All that will run in the container docker will be a son of 2312 and the process tree will attach under that “node”.

In this image we have two running containers, one running something related to the java and the other has an open shell (bin/bash). The two processes running in two different containers, viewed from the host machine’s point of view, may have PID 4312 and 6412. From the container point of view (for example if we connect with a shell in the containers) these two processes have the PID with value 1, and they are the parent process associated with the container itself.
So when the java process ends, everything ends (in the container on the left) because the process that supports everything is finished (the father process of the process tree).

For example when we launch “ps aux” in a container this ends immediately because after shown the output stops. The “ps aux” process has PID 1, in the context of the container.

--

--

Gioacchino Lonardo
Gioacchino Lonardo

Written by Gioacchino Lonardo

Computer Engineer, AI enthusiast, biker, guitar&bass player

No responses yet