$_ CLI In Depth
Learning progress 0%
lesson packages services cron

Init Systems & Services

5 min read Module 11: Packages, Services & Scheduled Jobs Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:19

PID 1 and its duties

The kernel does very little on its own after it starts. It hands control to a single program, which it runs as PID 1. That process must start the rest of the system, and it must also collect the orphaned processes that other programs leave behind, as the process lessons in the previous module explained. The init system does both jobs, and everything else on the machine is a descendant of it.

Init systems differ in how they describe the work. The oldest design, System V init, reads a table file and runs each line in turn. Modern systems such as systemd describe each service with a unit file and track its processes as a group. Alpine uses OpenRC, which uses small shell scripts that are run by a dependency-aware supervisor. The concepts are the same, and only the file formats differ.

inittab: the table format

The inittab format is simple enough to read in full. Each line has four colon-separated fields: an identifier, the run levels it applies to, an action, and the command to run. Actions such as sysinit run once at boot, and respawn runs the command again whenever it exits. Respawn is how a console login program stays available.

This course machine uses a short inittab. You can read it directly, and it is a useful model of how init works.

BASH1 lines
grep -v "^#" /etc/inittab | grep -v "^$" | head -n 6

The lines show the one-time startup tasks marked sysinit and the commands marked respawn. The first field of each line is empty in many entries, which is normal for the simple form of the table. The fields are easy to recognize once you know their order.

Services and their controls

A service is a long-running program that the init system manages. The usual commands to control a service are start, stop, restart, and status. On a systemd machine they are systemctl subcommands. On an OpenRC machine they are rc-service subcommands. Those commands need root, because they change the state of the machine, but the status query is often available to users.

The important habit is to ask the init system rather than the process table when you want to know whether a service is supposed to run. A process can be running after it was stopped, and a service can be configured but not started. The init system holds the configuration and the intended state.

Runlevels and boot order

A runlevel is a named set of services that should be running. Traditional systems had numbered runlevels, such as single-user mode and multi-user mode, and the init table selected the services for each one. Modern init systems often replace runlevels with targets or dependency graphs, but the goal is the same: start the right things in the right order, and skip the rest when booting into a minimal state.

Order matters because services depend on each other. A network service needs the network. A database needs the disk. The init system uses the dependency declarations to decide what can start in parallel and what must wait.

Dependencies between services have a practical consequence. When a service that others depend on is stopped, the init system may stop its dependents as well, or it may refuse to stop it until they are stopped first. Read the dependency declarations before you restart a core service on a busy machine, because a restart can take down a chain of other services for a short time. The same care applies at boot, where a service that waits for a disk or a network can delay the rest of the system if its dependency never becomes ready.

Startup scripts also run with a limited environment, and they often run before the disks you expect are mounted. A script that assumes a home directory or a writable log path can fail at boot even though it works when you run it by hand. Good startup scripts check their prerequisites, write a clear message when a prerequisite is missing, and exit with a status the init system can report. The logs described in the next unit are where those messages end up.

Restarting and supervision

A supervised service is restarted when it exits, and the init system keeps track of how often that happens. A respawn rule in inittab is the simplest form of supervision. Modern init systems add limits on restart rates, so that a service that crashes at once does not keep the machine busy. The process supervisor you built in the previous module applies the same idea at small scale.

Note

This lab machine has no service manager that you can control. The inittab file is read-only to a user, and no OpenRC or systemd is running. The lessons describe the commands you would use on a real Alpine or Debian system, and the lab shows the files that define the boot behavior.

Hands-on: read the boot table

Save the startup entries of the boot table in a file, and count the respawn entries. The file tells you which programs the system keeps running and how the table is organized.

BASH3 lines
grep -n "sysinit" /etc/inittab > sysinit.txt
grep -c "respawn" /etc/inittab > respawn.txt
cat sysinit.txt

The first file lists the line numbers and text of the one-time startup entries. The second holds the number of respawn entries. Compare the two files with the description above, and note which entry is a respawn for a console.

Terminal lab · 2 steps · real Linux in your browser

Read the boot table

Find the sysinit entries in inittab and count its respawn entries.

01
Find the sysinit entries
The sysinit action runs a command once at boot. grep -n finds those lines in /etc/inittab and prints their line numbers. Save the output in sysinit.txt. ``bash grep -n "sysinit" /etc/inittab > sysinit.txt `` Each line in the file should contain the word sysinit.
Show hint for step 1
Use grep -n with the word sysinit, and redirect to sysinit.txt.
02
Count the respawn entries
The respawn action restarts a command when it exits. Count the matching lines in inittab and save the number in respawn.txt. ``bash grep -c "respawn" /etc/inittab > respawn.txt `` The file holds one number, and it should be at least 1 on this machine.
Show hint for step 2
Use grep -c with the word respawn.
Check yourself Question 1 of 4
Concept Check The init process recall

Which process ID belongs to the init system, which starts the rest of the system?

Recap & Key Takeaways

PID 1 is the init system, which starts the boot tasks, runs the services, and collects orphaned processes.
In the inittab format, sysinit runs once at boot and respawn restarts a program each time it exits.
Service management commands need root, but the intended state is held by the init system, so ask it rather than the process table.
Dependency order decides what starts in parallel, and restart limits stop a crashing service from taking the machine.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue