</>EmbeddedInterview

What does the init process (PID 1) do, and what special rules apply to it?

MediumEmbedded Linux & Boot

Short answer: PID 1 is the first user-space process. It brings the system to a working state (mounts filesystems, starts daemons, starts login terminals or the main application) and then supervises it. It must never exit (the kernel panics if it does), it becomes the parent of every orphaned process so it must reap zombies, and the kernel does not deliver signals to it that it has not installed a handler for.

Typical jobs of init

  1. Mount /proc, /sys, /dev (devtmpfs), /tmp, /run, and remount the root read-write if needed.
  2. Set the hostname, load kernel modules, start udev/mdev to create device nodes and load firmware.
  3. Start services in the right order (logging, networking, the product application).
  4. Start getty on the console/serial lines so users can log in.
  5. Watch services and restart them, handle shutdown/reboot (SIGTERM to everything, unmount, sync, then reboot() syscall).

Special requirements

  • Must not die. If PID 1 exits or crashes, the kernel reports "Attempted to kill init!" and panics. Embedded products often rely on this plus panic=5 to reboot automatically.
  • Reaps orphans. When a parent dies, its children are re-parented to init (or to a "subreaper"). Init must call wait() on them, otherwise zombies accumulate.
  • Signal protection. The kernel ignores signals sent to PID 1 unless init has a handler for them, so even kill -9 1 from root does nothing. This also matters in containers: a shell script as PID 1 will not stop on SIGTERM unless it traps it, which is why tools like tini exist.

Common inits

Init Configuration Typical use
BusyBox init /etc/inittab + shell scripts tiny images, Buildroot
SysVinit runlevels, /etc/init.d/ scripts in order older systems
systemd unit files, dependency graph, parallel start, journald, watchdog larger devices, Yocto default for many BSPs
Your application init=/usr/bin/app single-purpose appliances

Running your application directly as init is possible but you then take on all of these duties (mounting, reaping zombies, handling shutdown), which is why most products still use a small init.