Experiment Six: Analyzing the process of creating a new process for the Linux kernel

Source: Internet
Author: User

20135108 Li Zeyuan

  1. Reading comprehension task_struct data structure http://codelab.shiyanlou.com/xref/linux-3.18.6/include/linux/sched.h#1235;

  2. Analyze the kernel processing process of the fork function Sys_clone, understand how to create a new process and how to create and modify task_struct data structure;

  3. Using the GDB trace to analyze a fork system calling the kernel handler Sys_clone, verifying your understanding of creating a new process for the Linux system, it is recommended to complete the experiment in the lab Building Linux virtual Machine environment.

  4. Paying special attention to where the new process starts? Why does it go smoothly? That is, the execution starting point is consistent with how the kernel stack is guaranteed.

  5. According to the knowledge of this week, we analyze the system call processing process of the fork function, write a signed blog, and in the blog article "real name (and the name of the final application certificate must be consistent) + Original works reproduced please specify the source +" Linux kernel Analysis "MOOC Course/http mooc.study.163.com/course/ustc-1000029000 ", the specific requirements of the blog content are as follows:

    1. Topic self-proposed, the content revolves about how the Linux system creates a new process;

    2. Can combine experiment, draw stack state to execute flowchart, etc.;

    3. The blog content needs to carefully analyze the new process start point and the corresponding stack state.

    4. Summary section need to clarify your understanding of the "Linux system to create a new process"

    5. Open the shell terminal and execute the following command:

      CD Linuxkernel

      RM-RF Menu

      git clone https://github.com/mengning/menu.git

      CD Menu

      MV Test_fork.c test.c

      Make Rootfs

      You can see that the MENUOS has already included the Fork command after the boot.


      1

      Debug mode can be opened by adding-s-s startup parameters

      Qemu-kernel LINUX-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD Rootfs.img-s-S

      Open GDB for remote debugging

      Gdb

      File Linux-3.18.6/vmlinux

      Target remote:1234

      Set breakpoints

      b sys_clone

      b do_fork

      b dup_task_struct

      b copy_process

      b copy_thread

      b ret_from_fork

      Experimental Analysis:

      The experiment shows that the fork () function creates a new process that is implemented by the following series of functions:

      Copy_thread (), copy_process (), Dup_task_struct (), Do_fork (), Sys_clone (), fork () Ork ()

      Experiment Summary:

      The three main management functions of the operating system include: Process management, memory management, file system.

      Fork, Vfork, clone three system calls can create a new process, and all by calling Do_fork to achieve;

      Linux creates a new process by replicating the parent process;

      From the user-state code, the fork () function returned two times, that is, in the parent, child process each return, where the parent process return code is a child process PID, the child process return code is 0.

      A negative value is returned when the fork () function call fails, and there are 2 main reasons for the failure:

      1, the current number of processes has reached the system specified upper limit, then the value of errno is set to Eagain (one-Try again);

      2, the system memory is insufficient, then the value of errno is set to Enomem (out of memory).

      About the init process creation:

      Daosh a Start_kernel ... cpu_idle

      Life two Kernel_init Kthreadd

      Secondary 30 1 2

      Sansheng 1th process is the ancestor of all user-state processes the 2nd process is the ancestor of all kernel threads

Experiment Six: Analyzing the process of creating a new process for the Linux kernel

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.