Overview

This article describes how to attach gdb (GNU Project debugger) to a program that is already running using the gdb [1] command, which is a source-level debugger, capable of breaking programs at any specific line, displaying variable values, and determining where errors occurred. Currently, it works for C, C++, Fortran, Modula 2 and Java programs.

Step 2.1 Attach gdb to a program that is already running

This is useful for debugging processes that started up, but crashed when you perform a particular task.

(If the program is running as root, use sudo gdb instead of just gdb above.)

Continue the <program>:

(gdb) continue

The program will continue running. Now you can perform any actions necessary to reproduce the crash. If the program hangs but doesn’t crash you can press ctrl+c in gdb while the program is frozen and then continue with the next step.