You can attach to a running process with gdb -p PID
.
If one want to attach a process, this process must have the same owner. The root is able to attach to any process.
Yes. You can do:
gdb program_name program_pid
A shortcut would be (assuming only one instance is running):
gdb program_name `pidof program_name`
Yes you can. Assume a process foo
is running...
ps -elf | grep foo look for the PID number gdb -a {PID number}
Easiest way is to provide the process id.
gdb -p `pidof your_running_program_name`
Please get the full list of option in man gdb
command.
In case there are multiple process for the same program running, then the following command will list the processes.
ps -C program -o pid h
<number>
Then the output process id (number) can be used as argument to gdb.
gdb -p <process id>
ps -elf doesn't seem to show the PID. I recommend using instead:
ps -ld | grep foo
gdb -p PID
The command to use is gdb attach pid
where pid is the process id of the process you want to attach to.
Source: Stackoverflow.com