Linux system Fork Execution Process __linux

Source: Internet
Author: User

Zhengdelen original works reproduced please indicate the source of "Linux kernel Analysis" MOOC course
http://mooc.study.163.com/course/USTC-1000029000
First, configure the environment:
First of all, we have the environment configuration completed
Enter in the lab building

RM menu–rf
git clone https://github.com/mengning/menu.git
CD menu
mv test_fork.c test.c make
rootfs

After we started menuos, I found fork had been added to the menuos.


Second, the Tracking debugging fork
Enter Qemu–kernel ... /linux-3.18.6/arch/x86/boot/bzimage–initrd.. /rootfs.img–s–s
Then enter at another terminal

GDB
(gdb) file Linux-3.18.6/vmlinux
(gdb) target remote:1234 (gdb)
b sys_clone
(gdb) b do_fork
( GDB) b dup_task_struct
(GDB) b copy_process (gdb) b
copy_thread
(gdb) b ret_from_fork

The process of tracking fork after setting a breakpoint
First triggers the Sys_clone system call

and then enters the Do_fork function

, which is invoked in the Do_fork function copy_process

in Copy_process call dup_task_struct and Copy_thread


Last Call Ret_from_fork () Fork

Complete the process we use the flowchart to represent:
br> iii. Summary
When Linux creates a new process, it may use the Sys_vfork sys_clone sys_fork system call, but all three system calls invoke the Do_fork function, and Do_fork calls Copy_ Process to copy the resources of the parent process to the child process. There are various copy_xxx functions in the copy_process to replicate initialization work. After the work is done, the ret_from_fork is executed, which is the starting point for the child process.

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.