Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Init process on UNIX and Linux systems
The Init process is the parent of all processes in UNIX and Linux systems, executed by the kernel during system boot. Its primary role is to create processes from configuration stored in /etc/inittab. Init spawns getty processes on terminal lines for user logins and controls all autonomous system processes required for proper operation.
After reading /etc/inittab, init determines how the system should be configured for each runlevel and sets the default runlevel. Init then starts all background processes after establishing the system's operational state.
Process Hierarchy
Runlevels
A runlevel is a software configuration that allows only a selected group of processes to exist. Init can operate in eight runlevels (0-6 and S/s), with each runlevel defining which processes should be running. The processes for each runlevel are defined in /etc/inittab.
| Runlevel | Function |
|---|---|
| 0 | System halt |
| 1 | Single-user mode (maintenance) |
| 2 | Multi-user mode without networking |
| 3 | Multi-user mode with networking |
| 4 | User-defined (typically unused) |
| 5 | Multi-user mode with networking and GUI |
| 6 | System reboot |
| S or s | Single-user mode (alternate) |
Boot Process
During system boot, init looks for an initdefault entry in /etc/inittab to determine the initial runlevel. If no such entry exists, the system prompts for a runlevel at the console. Init then starts all processes defined for that runlevel and waits for one of three conditions:
A descendant process dies
A power failure signal (SIGPWR) is received
A runlevel change is requested via
telinit
Changing Runlevels
Runlevels can be changed using the telinit command, which sends signals to init. When changing runlevels, init sends SIGTERM to processes not defined in the new runlevel, waits 5 seconds, then forcibly terminates them with SIGKILL.
telinit 3 # Switch to runlevel 3 telinit q # Re-examine /etc/inittab telinit 0 # Halt system
Power Management
When init receives a power failure signal, it reads /etc/powerstatus to determine the appropriate action:
| Status | Action |
|---|---|
| F (FAIL) | Power failing, execute powerwait/powerfail entries |
| O (OK) | Power restored, execute powerokwait entries |
| L (LOW) | UPS battery low, execute powerfailnow entries |
Telinit Commands
The telinit utility is linked to /sbin/init and accepts single-character arguments to control init's behavior:
| Command | Action |
|---|---|
| 0-6 | Switch to specified runlevel |
| Q or q | Re-examine /etc/inittab |
| S or s | Switch to single-user mode |
| U or u | Re-execute init (preserving state) |
| a, b, c | Process only entries with these runlevels |
Conclusion
The Init process serves as the foundation of UNIX and Linux systems, managing all system processes through runlevels defined in /etc/inittab. It provides controlled system startup, runlevel transitions, and graceful shutdown capabilities. Understanding init is crucial for system administration and troubleshooting boot-related issues.
