Sobes.tech
Middle

What are zombie processes?

sobes.tech AI

Answer from AI

A zombie process (defunct process) is a process that has completed execution but still has an entry in the process table because its parent process has not yet retrieved its exit status. It does not consume CPU resources but occupies a PID.

Lifecycle:

  1. Fork: The parent process creates a child process (fork()).
  2. Child termination: The child process terminates (exit()). The kernel releases its resources but retains some information (PID, exit code).
  3. Parent waiting: The parent process must retrieve the child's termination information (wait() or waitpid()). This allows the kernel to fully remove the child's record.
  4. Zombie: If the parent does not call wait() before the child's termination, the child becomes a zombie.

Problems:

  • They occupy a PID, which can lead to exhaustion of available PIDs.
  • They may indicate issues in the parent process that does not handle child termination.

Identification methods:

# Find processes in zombie state (Z)
ps aux | grep Z

Solutions:

  • The parent process should correctly use wait() or waitpid() to collect the termination status of child processes.
  • If the parent process has terminated but its zombie child remains, the zombie is adopted by the init process (PID 1), which correctly calls wait() to clean it up.
  • In extreme cases (rare), it may be necessary to restart the parent process. Restarting the system will guaranteedly remove all zombie processes.