Attach gdb to running process – How to attach gdb with running process

Attaching gdb with running process

Attach gdb to running process: This article is all about knowing the concepts to debug a running application.

Many times when we work with any application, we need to debug a running application by attaching debugger with process during runtime.

So, the command used to attach the gdb with a running process is

gdb <PROCESS NAME> <PROCESS ID>

And the command used to search the process information like Process ID is

ps -elf | grep <Process Name>

Let’s see an example how to attach gdb debugger to a running process :

gdb attach to running process: Suppose we have a running process named “authenticator

To get the process information first

ps -elf | grep sample authenticator

As a result we will get process information including Process ID and others as below

0 S active 2009 1989 86 80 ... 00:00:14 ./authenticator

So here the process id we got 2009. Now by using the below command we will attach the gdb debugger with process.

gdb authenticator 2009

Note: If root permission is required then use below command

sudo gdb authenticator 2009

Which will give gdb command prompt

Reading symbols from /lib64/ld-linux-x86-64.so.2…Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.21.so…done.
done.
__lll_lock_wait_private () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
95 ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S: No such file or directory.
(gdb)