Linux kernel boot trace

Source: Internet
Author: User

Description, this article for me to learn Monensin Teacher's Linux kernel lesson of a little summary, and as a class homework.

Has highlighted, "Linux kernel Analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000

First, the preparation: The Linux kernel will be compiled, and debugging information will be compiled in.

Use the Make Menuconfig command in the Linux root to enter the configuration interface; down to the kernel hacking option and enter;

Then find the "compile-time checks and Compiler Options" option and enter it, then find "compile the kernel with debug info" by the SPACEBAR to select, then save exit. Then make compiles

Second, start debugging information

We have created a simple file system rootfs here, and the process is not detailed.

Enter the code root directory, using QEMU to model the specific machine:qemu-kernel arch/x86/boot/bzimage -initrd./rootfs.img-s-S

-S prepares for back GDB commissioning

-S then hangs after system startup, so we Debug.

If it starts, it stops.

Start GDB start tracking: A separate shell window is required.

The file vmlinux loads the symbol table of the system, and then lets GdB and the startup Linux establish a connection to target remote:1234.

Third, start tracking the Linux kernel boot process

1, the Linux kernel is starting from the Start_kernel function, so we first hit the breakpoint in Start_kernel here.

You can see that when we execute C, we break to start_kernel here. Here we combine the code to analyze.

For example, Init_task is the first kernel process pid=0 (that is, the following idle process, which we will detail later), the structure of the initialization, No. 0 is Start_kernel, this is the

The information for this process is written to the process structure body. Start_kernel This function is the starting point of the Linux kernel, he mainly completed the system before the start of the initialization work, here only to Mark I know (sorry)

2. Init process Start

Here we focus on the last call of the Star_kernel function Rest_init (), which we can think of as initialization is complete. Break it off.

This rest_init the function code as follows, he mainly through Kernel_thread (call Do_fork) created two process init, kthread.

init--Process Entry Kernel_init (). We look at Kernel_init this function of the START process, in fact, he is, looking for each directory in the INIT program to use the shell form to start, until found,

So here we actually start the second process of the system, and we usually see the init process.

The code here does not get PID, so we can not print it out, but we know that this PID should be 1, because the PID is incremented. --someone would ask, here is actually two

Look at the following this is my Linux system file structure and process list, you should see it i sbin below the init, so my 1th process for the/sbin/init.

3, Kthread process start.

For example, the Kthreadd process is created shortly thereafter. Kthreadd This process function inside is a dead loop. This is the third process, so it can be inferred that the PID is 2

For example, when the process is created to the next, we see a PID of 2

4. Idle Process

Well, now that we've created Process 1 and 2nd, we'll go back to process number No. 0. We said before that Start_kernel is number No. 0, we continue to see how he changed back to the No. 0 process.

For example, the final call to Cpu_idle_loop is a dead loop.

Summary: The Linux system starts with Start_kernel, and he is also the first process idle entry function. The process then creates the INIT = 1 process and Kthreadd = 22 processes.

The focus is on the idle process, which is not do_fork out of the process, he is made. The rest of the process is a 1-process fork.

Linux kernel boot trace

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.