How can I debug the children after a fork?

How can I debug the children after a fork?


Depending on the tools available there are various ways:



Your debugger may have options to select whether to follow the parent or
the child process (or both) after a fork(), which may be
sufficient for some purposes.



Alternatively, your debugger may have an option which allows you to
attach to a running process. This can be used to attach to the child
process after it has been started. If you don't need to examine the very
start of the child process, this is usually sufficient. Otherwise, you
may wish to insert a sleep() call after the fork() in the
child process, or a loop such as the following:




{
volatile int f = 1;
while(f);
}



which will hang the child process until you explicitly set f to 0
using the debugger.



Remember, too, that actively using a debugger isn't the only way to find
errors in your program; utilities are available to trace system calls
and signals on many unix flavours, and verbose logging is also often
useful.






Home FAQ