Topics / Embedded Linux & Boot / Q5
What does the init process (PID 1) do, and what special rules apply to it?
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
- Mount
/proc,/sys,/dev(devtmpfs),/tmp,/run, and remount the root read-write if needed. - Set the hostname, load kernel modules, start
udev/mdevto create device nodes and load firmware. - Start services in the right order (logging, networking, the product application).
- Start
gettyon the console/serial lines so users can log in. - Watch services and restart them, handle shutdown/reboot (
SIGTERMto everything, unmount, sync, thenreboot()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=5to 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 1from root does nothing. This also matters in containers: a shell script as PID 1 will not stop onSIGTERMunless it traps it, which is why tools liketiniexist.
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.