Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug the child process after fork() in gdb?

Tags:

c

fork

gdb

After calling fork,the current process will call exit(0).

But the child will continue.

switch(fork())
{
  case -1:
    exit(1);
  case 0:
    //child process,continue
    break;
  default:
    //the current process,exit
    exit(0);
}

How can I continue debug the child process in this case?

like image 275
cpuer Avatar asked Jun 01 '11 09:06

cpuer


People also ask

How do I debug child processes?

Once you install the power tool from the Visual Studio Gallery, a new menu item will appear on the “Debug” menu under the “Other Debug Targets” sub-menu. When you open the settings page, you'll see a checkbox to enable child process debugging.

How do I enter a child process in GDB?

By default, when a program forks, GDB will continue to debug the parent process and the child process will run unimpeded. If you want to follow the child process instead of the parent process, use the command set follow-fork-mode . Set the debugger response to a program call of fork or vfork .

What is follow-fork-mode?

If you want to follow the child process instead of the parent process, use the command set follow-fork-mode . set follow-fork-mode mode. Set the debugger response to a program call of fork or vfork . A call to fork or vfork creates a new process.


1 Answers

Look at this. Use:

set follow-fork-mode <mode>

Set the debugger response to a program call of fork or vfork. A call to fork or vfork creates a new process. The <mode> argument can be:

parent: The original process is debugged after a fork. The child process runs unimpeded. This is the default.

child: The new process is debugged after a fork. The parent process runs unimpeded.

like image 87
Mihran Hovsepyan Avatar answered Oct 22 '22 01:10

Mihran Hovsepyan