开发者

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

开发者 https://www.devze.com 2023-03-10 02:58 出处:网络
After calling fork,the current process will call exit(0). But the child will continue. switch(fork()) { case -1:

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 p开发者_如何学Pythonrocess,exit
    exit(0);
}

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消