A run level is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init for each of these run levels are defined in the /etc/inittab file. Init can be in one of eight run levels, 0\(en6 and S or s. The run level is changed by having a privileged user run /sbin/telinit, which sends appropriate signals to init, telling it which run level to change to.
After init is invoked as the last step of the kernel booting, it looks for the file /etc/inittab to see if there is an entry of the type initdefault (see inittab(5)). initdefault determines the initial run level of the system. If there is no such entry or no /etc/inittab at all, a run level has to be entered at the system console.
Run level S or s bring the system to single user mode and do not require an /etc/initttab file. In single user mode, /bin/sh is invoked on /dev/console.
When entering single user mode, init reads the console's ioctl(2) states from /etc/ioctl.save. If this file does not exist, init initializes the line at 9600 baud and with CLOCAL settings. When init leaves single user mode, it stores the console's ioctl settings in this file so it can re-use them for the next single-user session.
When entering a multi user mode the first time, init performs the boot and bootwait entries to allow file systems to be mounted before users can log in. Then all entries matching the run level are processed.
When starting a new process, init first looks if the file /etc/initscript exists. If it does, it uses this script to start the process.
Each time a child terminates, init records the fact and the reason it died in /var/run/utmp and /var/log/wtmp if these files exist.
After it has spawned all of the processes specified, init waits for one of its descendant processes to die, a powerfail signal, or until it is signaled by /sbin/telinit to change the system's run level. When one of the above three conditions occurs, it re-examines the /etc/inittab file. New entries can be added to this file at any time. However, init still waits for one of the above three conditions to occur. To provide for an instantaneous response, the Q or q command can wake up init to re-examine the /etc/inittab file.
If init is not in single user mode and receives a powerfail signal, special powerfail entries are invoked.
When init is requested to change the run level, it sends the warning signal SIGTERM to all processes that are undefined in the new run level. It then waits 5 seconds before forcibly terminating these processes via the kill signal SIGKILL. Note that init assumes that all these processes (and their descendants) remain in the same process group which init originally created for them. If any process changes its process group affiliation it will not receive these signals. Such processes need to be terminated separately.
/sbin/telinit can also tell init how much time it should wait between sending processes the TERM and the KILL signal; default this is 5 seconds, but it can be changed by the -t sec option.
/sbin/telinit can be invoked only by users with appropriate privileges.
Runlevels 7-9 are also valid, though not really documented. This is because "traditional" Unix variants don't use them. In case you wonder, runlevels S and s are in fact the same. Internally they are aliases for the same runlevel - this is just a leftover from the systems the author used to use when writing sysvinit.
/etc/inittab /etc/initscript /dev/console /etc/ioctl.save /var/run/utmp /var/log/wtmp /dev/initctl