Sunday 4 September 2011

Debugging Running Process in Linux

A running process may not behave in a expected manner. This calls for anatomy of the running process.
There are various ways in which we can debug and understand the current state of the process.

Below are the three ways which i am familiar with and have been doing.
1. Using gdb command.
        gdb can be attached to a running process then using  breakpoint, watch and backtrace we can analyze the process behaviour and zero down to the location affecting the process behaviour.

2. Generating core dump of the running process
            core dump of the running process can be created using kill -11 command. The best part of this is core dump captures the current state of the process. The core dump can be analyzed without the need of the running process and at leisure.

3. Using gstack.
      This dumps the stack trace of all the running threads of the process. Running gstack on the process at different intervals gives a perspective of the process, number of threads and the methods taking up the time of the running threads.