27

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,167
  • 6
  • 47
  • 91

3 Answers3

46

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,455
  • 3
  • 45
  • 58
  • 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,489
  • 11
  • 24
3

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

gdb attach $(pgrep -f myApp) -ex cont
Dan
  • 1,057
  • 10
  • 13