32

Everytime I attach to a process using gdb, it will stop the target program, and I need to type 'cont' to let it go. Is there a way to attach to a process without stopping it? This makes things easier if the process will behave differently if it stops for a while.

Kan Li
  • 8,557
  • 8
  • 53
  • 93
  • Why would you attach and continue immediately? My use case has been attach > Set a breakpoint > continue. – talekeDskobeDa Jun 17 '20 at 10:48
  • @talekeDskobeDa You attach and continue immediately to catch a crash in the debugger. In this case, there is no need for a breakpoint, and stopping the program can have side effects. – Graham Leggett Mar 08 '23 at 21:49

3 Answers3

48

I know there is already a fine answer for this, but I prefer not using an additional file.

Here is another answer:

gdb attach $(pidof process_name) -ex cont
dashesy
  • 2,596
  • 3
  • 45
  • 61
  • 1
    I had to disable pagination, because on attach there were too many threads, and gdb did not perform 'continue' before user intervention: `gdb -iex "set pagination off" -q -ex cont -p $PID` – Alex Cohn Apr 27 '22 at 14:19
15

You can't make it not stop. You can however instantly continue... Create a simple batch script which will attach to a specific process and instantly continuing execution after attaching:

gdb attach $1 -x <(echo "cont")

./attach PID

Community
  • 1
  • 1
QuantumBlack
  • 1,549
  • 11
  • 27
3

For when you don't know the PID of the process...

gdb attach $(pgrep -f myApp) -ex cont
Dan
  • 1,112
  • 11
  • 14