Learning Linux kernel initialization with cainiao

Source: Internet
Author: User

Note: Most of the content below is taken from the Linux kernel programming entry and the Linux kernel complete annotation.

Looking at the kernel source code intermittently, I found that many knowledge points are not very clear, especially for some basic operating systems. Although I saw a block device, I couldn't summarize it. This article seems to have been updated a long time ago and has never been published. I 've been busy recently. I 've been to many colleagues and have considered other companies. However, if you have been working for less than one year, you cannot leave without authorization. Although busy, I still learned a lot. Gradually exposed to the Linux application layer. It is found that there are many differences between applications and drivers, various requirements, various interfaces, various designs, and various implementations. Well, I will always learn well later. For the kernel, take a look at it. If you don't understand it once, it will be the second time and the third time. I believe it will always be understood. Fighting ........

Only one main function is initialized under init.

First, use setup. sProgramThe obtained program parameters set the system's root file device number and some memory global variables. These memory variables indicate the start address of the primary memory, the memory variables owned by the system, and the end address of the high-speed buffer memory. If you also define a virtual disk (ramdisk), the primary memory will be reduced as appropriate.

Then, the kernel initializes all the hardware. Including the trap door, block device, character device, and tty, including manually creating the first task (Task 0 ). After all initialization is complete, set the interrupt flag to enable the interrupt.

After the entire kernel is initialized, the kernel switches the execution right to the user module, that is, the CPU is switched from the 0 privilege level to the 3rd privilege level. Then the system calls the create process function fork () for the first time to create a sub-process for running Init.

In this process, the system will run the console program. If the Console environment is successfully created, a sub-process is generated to run shell program/bin/sh. If the child process exits and the parent process returns, the parent process enters an endless loop, continues to generate the child process, and executes the shell program/bin/sh again in the child process, the parent process continues to wait.

For Linux, all tasks are executed in user mode, including many system applications, such as shell programs and network subsystem programs.

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.