Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging multiple forked processes in *nix

Are there any easy ways to debug forked child processes in *nix, without having to sleep them and create new gdb instances, using ps to get the child's pid? Are there any debuggers that do this?

like image 711
whalebiologist Avatar asked Feb 13 '26 20:02

whalebiologist


1 Answers

You can already do this using gdb. Here is how:

(gdb) set detach-on-fork off
(gdb) set follow-fork-mode child
(gdb) catch fork # use breakpoint if catch fork not available

Then at some point you will reach your fork. Jump over it and gdb should inform you there is a new process.

[New process 813]

At this point you should view the "inferiors"

(gdb) info inferiors
  Num  Description       Executable
* 2    process 813       /home/cnicutar/fork
  1    process 810       /home/cnicutar/fork

To switch to a different inferior, use

(gdb) inferior 1
[Switching to inferior 1 [process 810] (/home/cnicutar/fork)]
[Switching to thread 1 (process 810)]

(gdb) info inferiors
  Num  Description       Executable
  2    process 813       /home/cnicutar/fork
* 1    process 810       /home/cnicutar/fork

Hope this helps :-)

like image 102
cnicutar Avatar answered Feb 16 '26 10:02

cnicutar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!