I was debugging a Linux C program with CLion's internal debugger (which is gdb on Linux). The program forked a child process that was supposed to get suspended at the break point I set. But the debugger didn't stop there even if I had entered set follow-fork-mode child
inside the gdb panel. So how can I make that happen with CLion?

- 2,826
- 2
- 23
- 34
-
3Possible duplicate of [How set follow-fork-mode as child in debuger using CMake](http://stackoverflow.com/questions/34121840/how-set-follow-fork-mode-as-child-in-debuger-using-cmake) – Yoav Feuerstein Jan 21 '17 at 11:49
4 Answers
I followed answer posted by @MarkusParker, but instead of set auto-load safe-path /
I used set detach-on-fork off
to prevent disconnect from child process. This instruction works for me:
Set a break point at the beginning of your program (ie. the parent program, not the child program).
Start the program in the debugger.
Go to the debugger console (tab with the label gdb) in clion and enter
set follow-fork-mode child
andset detach-on-fork off
.Continue debugging.

- 408
- 4
- 14
-
3Since this is a popular answer, to avoid entering these commands every time you can create this file `~/.gdbinit` and add these commands inside (each in a separate line). This will probably only take effect if you are using your system's gdb. – tur1ng Sep 02 '22 at 12:30
according to this link debugger: Support multi-process targets
It's still not supported in Clion. set detach-on-fork off
will add a thread to the frame, but you still can't control the child process. And Clion
"treats exit of one of the inferiors as end of debugging session even-though others are still running".
I think there is a same issue with vscode.

- 31
- 2
Ensure that you set set follow-fork-mode child
before the fork.

- 424
- 2
- 8
-
5I confirmed this approach before and it didn't work. One can only debug through command line interface in this way instead of inside CLion. – DYS Aug 30 '16 at 09:09
-
1I'm experiencing that CLion disconnects remote debugging sessions when GDB follows the child process. – Jaime Hablutzel Feb 25 '18 at 16:59
-
1@JaimeHablutzel In that case you also need to `set detach-on-fork off`. – user7610 Jul 14 '21 at 15:32