33

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 continues
    break;
  default:
    // the current process exits
    exit(0);
}

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

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
cpuer
  • 7,413
  • 14
  • 35
  • 39

1 Answers1

51

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.

Stefan
  • 1,757
  • 1
  • 10
  • 8
Mihran Hovsepyan
  • 10,810
  • 14
  • 61
  • 111