init, telinit - process initialization process

Overview

/sbin/init [ -a ] [ -s ] [ -b ] [ -z xxx ] [ 0123456Ss ]
/sbin/telinit [ -t 秒 ] [ 0123456sSQqabcUu ]

description

Init

Init is the parent of all processes. Its primary task is from a file stored in / etc / inittab (see inittab (5)) inside the script creation process. This file is usually some make init derived in line each user can log getty records. It also controls a separate process for each unique system requirements.

Run Level

The so-called run level is a system configuration software environment, in this particular environment allows only a selected group of processes exist. init to different run levels derived process in / etc / inittab definition file. Init can start to run eight different levels: 0-6 and S or S . Run by the super-user level can by telinit command to convert, this command can convert the signals to the init , telling it which run level to switch.

Run level 0 , 1 , and 6 special run-level reserved for the system. Running off to level 0, level 6 operation to restart the computer, causing the computer to run the level 1 for single-user mode. Run level S is not used directly to us, more is to be called into operation when running certain level executable script 1. If you want more information about, see the man page for the shutdown (8) and inittab (5).

Although the run level 7-9 in the documentation, but can also be used. Their reason not to use just because "traditional" Unix variants do not use these operating level. In addition, run-level S and the run-level s are actually the same, they are just the same level within the operating system and has two different aliases.

System boot

When the kernel boot to the last step, the init process is started, it automatically searches for / etc / inittab file to see if there is a type initdefault (see inittab (5)) records. initdefault record initial run level decision system. Without this record (or no / etc / inittab ), then you must want to run level to enter the console input system.

Run level S or s to the system to single-user mode, this mode does not require / etc / initttab file. In single-user mode, / sbin / the sulogin will / dev / console open on the device.

When the single-user mode, the init will be from the file /etc/ioctl.save read console the ioctl (2) state. If the file does not exist, the init put the line is set to 9600 baud , and with the CLOCAL . When init when to exit single-user mode, it will be from the current console ioctl settings stored in this file for next time.

When you first enter the multi-user mode, the init performs the boot and bootwait records in order to mount the file system before the user can log on. And then perform the processes corresponding transport specified.

When starting a new process, the init checks for / etc / initscript file. If the file exists, then use the script to start the process.

If there is a file system in / var / run / utmp and / var / log / wtmp , then when each child process is terminated, the init will terminate and the reasons recorded information into these two files.

Change the operating level

When init After starting all child processes specified, it will continue to process the case detection system, such as: it is a child process is terminated, power failure, or by the telinit to change the operating level of the signal sent. When it receives one or more of these signals, it will automatically re-scan / etc / inittab file, and performs a corresponding operation. Therefore, a new record can be added to this file at any time. And, the init still waiting for the system sent the signal. After updating the various system files, if you want to get real-time updates, you can use the telinit Q or q command to wake up init it immediately re-testing / etc / inittab file.

If init is not in single-user mode and receives a power fail signal (SIGPWR), it reads the file / etc / powerstatus , and performs various operations as specified in the document:

F(AIL)
Power failure, providing power from the UPS. Execution powerwait and powerfail record.
O (K)
Power is restored, perform powerokwait record.
L (OW)
UPS power failure and the voltage is too low. Execution powerfailnow record.

If the file / etc / powrestatus does not exist or does not contain the contents shown above the letter F. , O or L , as the init will read the letter F. .

We do not use SIGPWR and / etc / powerstatus . Some users want to init to interact, you can use / dev / initctl control channel. Description In this regard, please refer to sysvinit source code package.

When init updated request run level, init will be sent to all processes that are not defined in the new run level a warning signal SIGTERM . After waiting five seconds, it will signal the forced interruption of all processes running SIGKILL . Note, init assumes that all these processes (including their descendants) are still in the init originally created them the same process group. If there is any process change their process group, then it can not receive these signals. Such a process, you need to manually terminate respectively.

TELINIT

/ sbin / telinit is a to / sbin / init soft links. It is used to inform a single character parameter init performs a corresponding operation. The following parameters are relevant:

0 , 1 , 2 , 3 , 4 , 5 or 6
Notification init run level switch to the specified run level
a, b, c
Tell init run only those / etc / inittab file is run level A , b or c of record
Q or q
Inform init to re-detect / etc / inittab file
S or s
Notification init run level switch to the single-user mode
U some u
Notification init automatic restart (hold), this action does not file / etc / inittab for re-testing. When you do this, run level must be in Ss12345 one, otherwise, the request will be ignored

telinit can also tell init twice SIGTERM and SIGKILL signal transmission time interval. The default is 5 seconds, you can use the -t sec to modify options.

telinit can only be executed by a user with appropriate privileges.

init by examining its own process ID to determine that he is init or telinit ; really init process is always No. 1 . From this point of view, we call telinit can be used only when init to knock on a few key less.

Environment Variables

Init Set the following environment variables for all child processes

PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin
INIT_VERSION
As the name suggests. In determining whether a script directly from the init useful when
RUNLEVEL
The current run level of the system
PREVLEVEL
Run level of the previous operation (only useful when changing run level)
CONSOLE
The system console. This variable is inherited from the kernel, if this environment variable is not defined, the init will use / dev / console as the default console

Startup Logo

May be (for example, LILO) passing some of the boot manager by the boot flag in the system to start the init , the Init takes several following:

-s, S, single
Start the system in single-user mode. When you start in this mode, / etc / inittab need to be checked, and will guide the implementation of rc script before the single user mode shell is started.

 

1-5
Definitions need to start the run level

 

-b, emergency
Do not run any startup scripts directly into single-user mode shell

-a, auto If you use the default command line increased from kernel boot (no user intervention), LILO boot manager word to the command line if that is the case, the init environment variable Note that you can not be the thing for any security evaluation - Of course, the user can manually enter the command on the line

xxx the -z the -z parameter is ignored. You can use this option to slightly expand the command line, so that it can get more space on the stack. Then Init can operate the command line, so that PS (1) shows the current run level.

interface

a monitor init / dev inside of the FIFO , / dev / the initctl , from which to obtain information. Telinit are also used for communication and the init. The interface is not fully documented. If you are interested init, you can learn src / directory init source files in the package initreq.h file.

signal

generating a signal in response to the init

Sigःuf
After receiving this signal, init be / etc / initrunlvl and / var / log / inirunlvl file will be checked. If either of these files exist and the file has run level ASCII characters, init will be converted to the corresponding new run level. This feature is only for backward compatibility! . Often the case that the file does not exist, the init performs similar telinit q such operations.

 

SIGUSR1
When receiving the semaphore, init will close and reopen its control FIFO, / dev / the initctl . This operation is useful for startup script after the / dev is remounted.
SIGINT
Typically, when a user presses CTRL-ALT-DEL key, the kernel will pass this signal to init. It performs the operation ctrlaltdel same.
SIGWINCH
When the keyboard has KeyboardSignal when the button is pressed, the signal is transmitted to the init kernel, it activates kbrequest operation.  

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11087946.html