On the INIT process

Source: Internet
Author: User

First, what is the init process

Before we introduce the INIT process, let's start by understanding what the process is.
1. Concept of the process

The so-called process is a running program in the system, the process is the concept of the operating system, whenever we execute a program, for the operating system is to create a process, in this process the operating system to allocate and release the process resources, you can think of the process is a program execution process.
Three special processes under 2.Linux

Linux has three special process idle processes (pid=0), init process (pid=1), and Kthreadd (pid=2)
The idle process is automatically created by the system and runs in the kernel state
The pid=0 of the idle process, its predecessor is the first process created by the system, and the only process that has not been generated by fork or kernel_thread. After the system is loaded, it evolves into a process scheduling and switching.
The Kthreadd process is created by idle through Kernel_thread and always runs in kernel space and is responsible for scheduling and managing all kernel processes.
Its task is to manage and dispatch other kernel thread kernel_thread, which will loop through a kthread function, which is to run kthread_create_list the Kthread maintained in the global list, when we call Kernel_ Kernel threads created by thread are added to this list, so all kernel threads are directly or indirectly kthreadd to the parent process.
The init process is created by idle via Kernel_thread, and after the kernel space is initialized, the INIT program is loaded
Here we mainly explain the init process, the INIT process is created by 0 processes, complete the initialization of the system, the system is the ancestor process of all other user processes
All processes in Linux are created and run by the Init process. Start the Linux kernel, start the init process in user space, and start other system processes. After the system boot is complete, init becomes the daemon monitoring system for other processes.
So the init process is one of the indispensable programs in Linux system operation, if the kernel cannot find the INIT process, it will try to run/bin/sh, and if it fails, the system startup will fail.

Second, operational level

The configuration file for the Init service is/etc/inittab
This is the Inittab configuration file before Centos7.

# inittab is only used by upstart for the default runlevel.## ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.## System initialization is started by /etc/init/rcS.conf## Individual runlevels are started by /etc/init/rc.conf## Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf## Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,# with configuration in /etc/sysconfig/init.## For information on how to write upstart event handlers, or how# upstart works, see init(5), init(8), and initctl(8).## Default runlevel. The runlevels used are:#   0 - halt (Do NOT set initdefault to this)#   1 - Single user mode#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)#   3 - Full multiuser mode#   4 - unused#   5 - X11#   6 - reboot (Do NOT set initdefault to this)# id:5:initdefault:

It describes the 6 runlevel of Init.
0 is shutdown

1 is a single user

2 is multi-user, not networked

3 is multi-user

4 is not used

5 is Xwindows, which is the interface.

6 is reboot

The init command is simple. Direct INPUT init + the mode you want to enter the line.
We can use the RunLevel command to query the current operating level of the system.
such as input: Init 0 is the shutdown

Init 3 is switching to multi-user

Init 5 is the switch to the interface

Init 6 is the reboot.
But don't set the Initdefault to 0 or 6.
But after Centos7, a new service systemd replaced the INIT,
Systemd is the next Linux system and Service Manager compatible with SysV and LSB initialization scripts. Here I can not only introduce, we are interested in self-study.

Third, the definition of the init runlevel

The run-level configuration for Init is in/etc/init, and these levels are defined in the/ETC/RC.D directory as follows:

[[email protected] rc.d]# lltotal 60drwxr-xr-x. 2 root root  4096 Jan  9 02:30 init.d-rwxr-xr-x. 1 root root  2617 Mar 23  2017 rcdrwxr-xr-x. 2 root root  4096 Jan  9 02:30 rc0.ddrwxr-xr-x. 2 root root  4096 Jan  9 02:30 rc1.ddrwxr-xr-x. 2 root root  4096 Jan  9 18:39 rc2.ddrwxr-xr-x. 2 root root  4096 Jan  9 18:39 rc3.ddrwxr-xr-x. 2 root root  4096 Jan  9 18:39 rc4.ddrwxr-xr-x. 2 root root  4096 Jan  9 18:39 rc5.ddrwxr-xr-x. 2 root root  4096 Jan  9 02:30 rc6.d-rwxr-xr-x. 1 root root   220 Mar 23  2017 rc.local-rwxr-xr-x. 1 root root 20199 Mar 23  2017 rc.sysinit

Here's the rc{0..6}. Directories corresponding to the corresponding levels are all the processes to start and close. Let's go inside and see.

[[email protected] rc3.d]# lsk01smartd k69rpcsvcgssd k95firstboot s13irqbalance S26udev-post            K02ODDJOBD k73winbind k99rngd s13rpcbind S28autofsk05wdaemon k74ntpd        S01sysstat s15mdmonitor s50bluetoothk10psacct k75ntpdate s02lvm2-monitor S22messagebus S55SSHDK10SASLAUTHD k75quota_nld S05RDMA S23networkmanager S80postfixk15htcacheclean K76yp Bind s08ip6tables s24nfslock s82abrtdk15httpd k84wpa_supplicant s08iptables S24RPCG         SSD s83abrt-ccppk30spice-vdagentd k87restorecond s10network s25blk-availability s90crondk50dnsmasq    K88SSSD s11auditd s25cups s95atdk50kdump k89netconsole s11portreserve S25netfs s99certmongerk60nfs k89rdisc s12rsyslog s26acpid s99localk 61NFS-RDMA K92PPPOe-server S13cpuspeed S26haldaemon 

The process that starts with K here is the one you want to close, and the one that starts with S is the process you want to start

[[email protected] rc6.d]# lsk01certmonger k25sshd k74haldaemon k84wpa_supplicant K90networkK0  1SMARTD k30postfix k74ntpd k85mdmonitor k92ip6tablesk02oddjobd k30spice-vdagentd      K75blk-availability k85messagebus k92iptablesk05atd k50dnsmasq k75netfs k87irqbalance          K92pppoe-serverk05wdaemon k50kdump k75ntpdate K87restorecond k95firstbootk10cups         K60crond k75quota_nld k87rpcbind K95rdmak10psacct k60nfs k75udev-post K88AUDITD k99cpuspeedk10saslauthd K61NFS-RDMA k76ypbind k88rsyslog K99lvm2-moni          Tork15htcacheclean K69RPCSVCGSSD k83bluetooth K88SSSD k99rngdk15httpd k72autofs     K83nfslock k89netconsole k99sysstatk16abrt-ccpp k73winbind K83RPCGSSD k89portreserve  S00killallk16abrtd       K74acpid K84networkmanager K89rdisc S01reboot 

Like the RC6.D directory is basically the process to be closed, only the two processes to be started by S00killall and s01reboot they are to end all processes and restart the system. The numbers in the file here represent their priority, and the smaller the number, the higher the priority to start. So when we put our own service in this directory, we should be cautious lest the process fail to start because the associated program he needs is not started.
PS: If you really accidentally set the init default run level to 0 or 6 workaround
We know that the init0 and 6 levels are corresponding to the shutdown and restart, if you set these two as the default operating level we are unable to enter the system, so we have to use the rescue system, the boot grub interface by E as follows:

Select kernel this line and press E

Enter 1 at the end of the command line (enter single-user mode), return back to the previous interface

Then press B to enter the single-user mode, we're going into single-user mode.

All we need to do is go into the/etc/inittab config file and change the last 0 or 6 to 3 and reboot the system.

On the INIT process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.