By default, when a process creates another process, GDB doesn't follow the execution of the child process. You must attach another instance of the debugger to this new process; this action lets you debug the parent and child concurrently.
You can now debug the child and parent processes concurrently, by alternating between the different sessions in the Debug view. When you click a session entry, you access the GDB instance attached to the corresponding process and any debugging actions you then perform (e.g., resuming execution, stepping through code) are applied to that process. This design lets you attach GDB instances to several child processes and debug all of them concurrently.
For information on the debugging controls, see Debug perspective controls.
When a program executes a fork() statement, GDB by default follows the parent code path. To make GDB follow the child code path instead, you must preset the right mode in the gdb utility.
set follow-fork-mode child
This strategy is handy when you always want to follow the code path of the child instead of the parent. If you want to debug into the child only occasionally, you can manually set this mode before the child process gets created. To do so, you must first verify that GDB is configured to stop on startup, so you have time to issue the necessary gdb command.
GDB lets the application run and create the child process. When this happens, GDB follows execution into the child when the program executes the fork() call.
For information on the debugging controls, see Debug perspective controls.