Multi-process Debugging method under LINUX __linux

Source: Internet
Author: User
#include < stdio.h >
#include < unistd.h >

int main ()
... {
if (fork () = = 0)
... {
printf ("Child Process say hello to you!");
Sleep (5);
Exit (0);
}
Else
printf ("Parent Process, Hello");

return 0;
}

1: You typically use GDB to debug a subprocess by inserting the sleep () statement in a subprocess. Run GDB to debug this program, wait until the child process is fork, get its process number, and then run GDB at the other terminal, with this process number attach on the child process, we can debug the child process. GDB childID (gdb) Attach childID

2: Another way is to set Follow-fork-mode as a child in GDB, which is used in the form of "set follow-fork-mode Child". The default GDB tracks the parent process. 3: Invoke the subroutine through System (): Method 1 applies. If the source files of the subroutine and the source files of the parent program are not shared, that is, you cannot set a breakpoint on the subroutine after the parent program, and you will not have the opportunity to set breakpoints after using Method 2, and you cannot debug. After using Method 2, it seems impossible to attach the child process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.