INIT process and system V init started in Linux-android System

Source: Internet
Author: User

INIT process and system V init started in Linux

I. INIT process and system V init started in Linux

1. first introduce the INIT process
The INIT process starts after start_kernel is executed, that is, after the kernel Initialization is complete. It is the starting point of all processes in the system. After the kernel completes the kernel boot, it is in this thread (process) the INIT program is loaded in the space. Its Process number is 1.
If System V init is used for startup, System V init is actually an INIT process.

2. Next we will introduce the/etc/inittab file.
The INIT program needs to read the/etc/inittab file as its behavior pointer. inittab is a descriptive (non-executive) Text of the behavior unit. Each Command Line has the following format: ID: runlevel: Action: in process, ID is the entry identifier, runlevel is the running level, action is the action code, and process is the specific execution program.
Generally, the ID must be within four characters. For Getty or other login program items, the ID must be the same as the TTY number. Otherwise, the Getty program will not work properly.
Runlevel is the identifier of the running level of init. It is generally 0-6 and S or S. The running levels 0, 1, and 6 are retained by the system, 0 is used as the shutdown action, 1 is used as the restart to the single-user mode, and 6 is used as the restart; S and S have the same meaning, indicating the single-user mode, the inittab file is not required, so it does not appear in inittab. In fact, when you enter single-user mode, init runs/sbin/sulogin directly on the console (/dev/console.
In general system implementation, 2, 3, 4, and 5 are used. In the RedHat system, 2 indicates that the multi-user mode is not supported by NFS, 3 indicates full multi-user mode (also the most common level), 4 is reserved for user customization, and 5 indicates xdm graphical login mode. The 7-9 level can also be used. Traditional UNIX systems do not define these levels. Runlevel can be multiple parallel values to match multiple running levels. For most actions, runlevel is executed only when it matches the current running level.
Initdefault is a special action value used to identify the default startup level. When init is activated by the core, it reads the initdefault item in inittab and obtains the runlevel, as the current running level. If there is no inittab file or there is no initdefault item, init will request input in the console.

3. analyze the process of system V init
> First,/etc/rc is executed. d/RC. sysinit is mainly used to start swap partition/check Disk/configure host name/check and mount file system/load and initialize hardware module and other functions;
> Then run the default run-level mode (for example, if the default run-level is set to 5 by ID: 5: initdefault, it will go to etc/rc. d/rc5.d directory to find and execute all the configuration files. In fact, all the configuration files under this directory are linked to/etc/rc. d/init. d. You can use the LS-l command to view the specific link relationship of files under the directory );
> Next, run/etc/rc. d/RC. local script file (this is the last script file executed by init, so you can add some commands that need to be executed before login in this file, it works with autoexec in the C root directory of windows or doson PC. bat works exactly the same );
> Finally, run the/bin/login program.
 
If the above initialization process ends normally, the user will initialize the environment and give control to shell.

2. Call of the system boot application initiated by the INIT process started by the Linux system and system V init

The above description shows that the INIT process will go to etc/rc during system startup. d/rc *. d directory to find and execute the default running-level configuration file. Obviously, in this process, you can add a configuration file to start our own applications. at the same time, we also noticed that in step 3 of the execution process of System V init, we will check and execute/etc/rc. d/RC. local script file, which can be used to start our own applications.
Therefore, we can draw the following conclusion:
1. Add a STARTUP script under/etc/init. d to create a link under the/etc/rc. d/.../directory.
In fact, most applications in the system are started in this way.
The syntax and writing of the script are not the key points described here. For more information, visit Baidu & Google.
2. directly add commands in/etc/rc. d/rc. Local. This script is called during startup.
For example, the content of RC. Local on F10 is as follows:
#! /Bin/sh
#
# This script will be executed * after * all the other init scripts.
# You can put your own initialization stuff in here if you don't
# Want to do the full sys V style init stuff.

Touch/var/lock/subsys/local
Add the application you want to start in the next day. For example, you can use the following method to start NFS:/etc/rc in some example. d/init. d/nfs restart (note the following. Restart is the parameter used to call the script)

By querying information, I suddenly remembered that I could pass parameters to the kernel through U-boot or similar boot programs, and specify the name and path of the started application through parameters, for example, init =/passion's Program (note: this is only part of the parameter. For details about the complete parameter, refer to the Boot Code or the introduction of the Kernel Parameter ). however, the time for starting the application at this time is not the same as the two methods above. This is started at the end of the kernel initialization, it is called when System V init is not started. of course, the applications started using the above two methods are not called at the same time.
 
Okay, close the job.

 

Related Article

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.