5.10. Debugging Running Processes

In addition to stand-alone programs, running processes can also be debugged using GNU debugger. The procedure is as follows:

1.
Start the process that you want to debug.
2.
Use the ps command to find the process ID of the running process.
3.
Start gdb.
4.
Load the file containing the symbol table into gdb.
5.
Use the attach command to attach to the running process to gdb.
6.
Continue debugging as usual.

In this section we shall attach to a process created by executing the sumf program that we created earlier in this chapter. This program requires input of two numbers. After starting, the process waits for the user to input these two numbers. You can open a new terminal window at this point and start gdb in the new ...

Get Linux Development Platform: Configuring, Using, and Maintaining a Complete Programming Environment, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.