So on *nix systems PID 1 is supposed to be the init process. Any processes
that lose their parent are *supposed* to be adopted by the init process so
it can reap them.

You find out a lot about this when dealing with Docker containers and java
processes. If your java process is PID 1 in the container, you’re going to
be in for a bad time...

Java process runs out of heap and spins in GC... so no signals handled
correctly... cannot kill container... restart Docker

Java process forks a shell script every 1s but doesn’t reap the dead
processes forked by the shell script... your container will run out of
handles... cannot kill container... restart Docker

This is why a lot of people will use a minimal init process in Docker
containers, eg tini (but there are others)

Now if we have someone running a Maven build inside a Docker image (really
nice with multistage Dockerfiles and COPY —from) and they do not understand
(or agree with) the need for a minimal init then the assumption that all
child processes will be reparented to PID 1 would be invalid.

Similarly if a child handles reparenting of its grandchildren when the
child dies then the PPID will stop there and not get to PID 1 until the
owner dies *and nobody else* steps up to adopt

Windows is a different case... no clue what goes on there

On Fri 23 Feb 2018 at 19:06, Tibor Digana <> wrote:

> Hi Michael,
> I found in C libraries documentation that PPID is =1 if the parent process
> has exited - called native exit().
> Would the child process see PPID=1 in other cases too, like parent abort()
> or segmentation fault? Can I rely on this on all platforms?
> It might be easy detection of parent process has finished.
> Thx
> Tibor
Sent from my phone

Reply via email to