If you're running Linux kernel 2.6, gdb will give you complete control. Go
here for details.
(This also applies if you're running HP-UX 11.x or later.)
If you're running Linux kernel 2.4 or something else, I'll quote from the above link, and insert my comment in
red:
Quote:
However, if you want to debug the child process there is a workaround which isn't too painful. Put a call to sleep in the code which the child process executes after the fork. It may be useful to sleep only if a certain environment variable is set, or a certain file exists, so that the delay need not occur when you don't want to run GDB on the child. While the child is sleeping, use the ps program to get its process ID. Or, just before the call to sleep, printf("%d\n",getpid());. Then tell GDB (a new invocation of GDB if you are also debugging the parent process) to attach to the child process (see section 4.7 Debugging an Already-running Process). From that point on you can debug the child process just like any other process which you attached to.
|
Remember that if you're running Linux 2.6, you can avoid the previous quotation and get
complete control.
If you're going to be doing stuff like this, it would do you good to browse through the
complete online gdb documentation. If you use that documentation frequently, as I do, you might wish to download it from
here (html tarball) or
here (other formats).
Hope this helps.