Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug a multithreaded hung process in Linux?

A multithreaded application hangs and it is not responding to any commands. I have tried following things without luck:

  1. Attach a process to gdb (error: (gdb) attach 6026 Attaching to process 6026 ptrace: Operation not permitted.)
  2. gstack (gstack just hangs like that)

Is there any good way to debug this process?

like image 365
Thangaraj Avatar asked Sep 05 '11 07:09

Thangaraj


People also ask

How do I see hung processes in Linux?

strace command gives you info on all system calls made by the process. For example, # strace -p 32287 Process 32287 attached - interrupt to quit recvfrom(34, If your process is really hanging, you might see strace result also hanging on a system call.

What is LWP in GDB?

The operating system's lightweight process (LWP) ID value for the thread. This ID is used in part for the OS to keep track of this thread for scheduling purposes. The GDB ID for the thread. This is the ID to use when specifying a specific thread in GDB commands.


2 Answers

Thanks for all your response. The problem is at kernel level. we used echo t > /proc/sysrq-trigger, which logs the stack of all the running process in /var/log/messages. This stack trace helped to analyze the problem.

From the stack trace, file system posted some waited event on behalf of the application process to other process (which is in defunct state) and waiting for the response indefinitely. Which results in hung state.

like image 115
Thangaraj Avatar answered Oct 13 '22 00:10

Thangaraj


Most likely somebody else already tracing this process. To find out who is doing it look at proc file system.

cat /proc/6026/status|grep TracerPid
like image 39
ks1322 Avatar answered Oct 12 '22 22:10

ks1322