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.