How child processes are managed in Linux

Published on 2026-09-12 by frfrand

What fork and exec do, why zombie processes exist and what they really mean, who adopts orphans, and why your container ignores the shutdown signal.

How child processes are managed in Linux

Short answer: on Linux a new process is born by copying an existing one (fork) and replacing its program (exec). When a child finishes it remains as a zombie until the parent reads its exit code with wait; if the parent dies first, the orphaned child passes to init (PID 1), which reaps it. In a container, your application is usually PID 1, and that is why it can ignore the shutdown signal.

On Linux there is no classic call to "create a process from scratch". There is one to copy itself, and another to replace the program you are running. Everything else comes from combining those two.

fork and exec

fork duplicates the current process. After the call there are two almost identical processes, with the same memory (shared intelligently until one writes to it) and the same open files. The only difference is the value returned by the call: to the parent it returns the child's identifier, and to the child it returns zero. That way each one knows who it is.

exec replaces the current process's program with another. It does not create anything: the identifier remains the same, what changes is the code being executed.

When your shell runs a command, it does exactly that: it copies itself with fork, and in the copy it calls exec with the program you requested.

It seems convoluted and it is very powerful: between fork and exec, the child can change things (redirect its input and output, change user, adjust limits). That is where shell pipes and redirections are implemented.

Zombies, which are poorly explained everywhere

When a process ends, it does not disappear completely. The kernel keeps a minimal entry with its exit code, waiting for the parent to read it with wait.

That intermediate state is a zombie.

Two important clarifications:

A zombie consumes almost nothing. It has no user memory, no CPU, no open files. It is a minimal entry in the kernel's process table. What it really retains is its process identifier.

You cannot kill a zombie. It is already dead. Sending it a signal does nothing. The way to remove it is for the parent to read its status, or for the parent to terminate.

So, why are they a problem? Because if a program creates many children and never calls wait, zombies accumulate and can exhaust the process table. The symptom is "cannot create more processes" with the machine apparently idle.

And the solution is never to kill zombies: it is to fix the parent.

Orphans, which are the opposite

If the parent terminates before the child, the child becomes an orphan. The kernel immediately assigns it to init (process 1) or, if it exists, to the ancestor marked as "subreaper" (systemd uses it, for example). That process is programmed to read the status of any child that terminates.

That is why an orphan never remains a zombie: init reaps it. It is also the mechanism by which a process "detaches" to run permanently in the background.

Why PID 1 is special, and your container suffers from it

Process 1 has different rules, and there is one that surprises everyone:

For process 1, signals have no default action.

For any other process, receiving the termination signal terminates it, even if its code does nothing about it. For process 1, if the program did not explicitly install a handler, the signal is ignored.

And in a container, your application is usually process 1.

Practical consequence: you send the command to stop the container, your application does not handle the signal, nothing happens. The engine waits for a deadline (in Docker, 10 seconds by default) and kills it by force. That is why every stop takes exactly that deadline and connections are cut abruptly.

Two solutions:

  • Handle the signal in your code and shut down gracefully: stop accepting new connections, finish the ones in progress, close the database, exit.
  • Use a minimal init as process 1 (Docker's --init option, or tini). That init handles signals, forwards them to your process, and also reaps orphans.

It is probably the process detail that has the most impact on day-to-day work and is explained the least.

How child processes are managed in Linux
How child processes are managed in Linux

Why child processes matter in production

A web application can start workers or auxiliary processes. When the main process ends, you need to know who supervises the others, how they receive shutdown signals, and whether they release resources. Running tasks without supervision can leave orphaned processes or interrupted jobs.

If you run an API or a worker on an ArduMaker VPS, define separate services when their lifecycles differ. Check systemctl status, journalctl -u service-name, and restart policies to understand what happened after a deployment. Do not confuse restarting the API with restarting a database.

Related: What is a worker · What is a Linux process.

Frequently asked questions

How do I remove a zombie process? It cannot be killed: it has already finished. You need to get the parent to call wait (by fixing it or restarting it); if the parent terminates, init adopts it and reaps it.

Do zombies fill up memory? No. They occupy a minimal entry in the process table. The risk is exhausting process identifiers if they accumulate by the thousands.

Why does docker stop take ten seconds? Because the application, running as PID 1, does not handle SIGTERM and Docker waits its default deadline before sending SIGKILL. It is fixed by handling the signal in the code or using --init (tini).

  • procesos
  • fork
  • señales
  • zombies
  • Linux

Keep reading

All articles · VPS plans