Using GDB to track the process of creating a new process
rm menu -rf git clone https://github.com/mengning/menu.git
mv test_fork.c test.c
执行fork,可以看到父进程子进程都输出了信息。
Using GDB for debugging
Qemu-kernel linux-3.18.6/arch/x86/boot/bzimage-initrd rootfs.img -s-s
Gdb
File Linux-3.18.6/vmlinux
Target remote:1234
Start setting breakpoints
Where does the new process start? Why does it go smoothly? That is, the execution starting point is consistent with how the kernel stack is guaranteed.
Ret_ From_ Fork determines the first instruction address of the new process. The child process starts at the ret_ From_ Fork. Because before ret_ From_ Fork, that is, in the copy_ thread () function * childregs = * Current_ pt_ regs (), this sentence assigns the regs parameter of the parent process to the kernel stack of the child process. * The Childregs type is Pt_ regs, which stores the parameters of the Save_ all in the stack, so it can be executed smoothly in the subsequent restore all.
Linux Kernel Analysis Sixth experiment