It is the first process executed by the kernel during the booting of a system. It is a daemon process which runs till the system is shutdown. That is why, it is the parent of all the processes. First of all, init reads the script stored in the file /etc/inittab. Command init reads the initial configuration script which basically take care of everything that a system do at the time of system initialization like setting the clock, initializing the serial port and so on.
By reading this file, init determines how the system should be set up in each runlevel and sets default run level.
After determining default runlevel for the system, init starts all background processes required to run the system. First it runs each of the kill script (their file name starts with a K) with a stop parameter. Then it runs all start scripts (their file name starts with an S) to start all services and applications.
A runlevel is a software configuration of Linux system which permits only a selected group of processes to exist. It defines what services are operating on the system.
Runlevels are identified by numbers. init can be in one of eight runlevels. It is changed by a privileged user run telinit, which sends appropriate signals to init to change runlevel.
There are many ways to change runlevels. To make the changes permanently, change the default level in the file /etc/inittab.
After all the processes, init waits for one of its descendent process to die, for a powerfail signal. Or wait until telinit signals to change the runlevel. When above conditions occur, it re-examines the /etc/inittab file. New entries can be added to this file any time.
When init is not in single user mode and receives a power fail signal (SIGPWR), it reads the file /etc/powerstatus. Based on the content of this file, init starts a command:
If file /etc/powerstatus doesn't exist or contains anything other than F, O, L, then init behaves as if it has read the letter F.
To interact with init, /dev/initctl control channel should be used rather than SIGPWR and /etc/powerstatus.
When a request to change the runlevel is send to init, init sends warning signal SIGTERM to all the undefined processes in the new runlevel. It then waits for 5 seconds before terminating processes via SIGKILL forcibly.
All these processes should remain in the same process group which was created by the init, otherwise they will not be able to receive these signals and they need to be terminated separately.
/sbin/telinit is linked up with /sbin/init. Telinit takes up an argument and signals init to perform the respective function.
Arguments are as follows with are one character each:
Default time to wait between sending the signals SIGTERM and SIGKILL is 5 seconds, but telinit can also ask init to change this time with the option -t sec.
Only users having appropriate privileges can execute telinit.
The init binary checks by the process ID whether it is init or telinit, init's process ID is always 1. so one can also use init instead of telinit as shortcut.