简体   繁体   English

在Linux中,不使用GDB进行实时调试,如何在挂起C程序时查找其状态?

[英]In Linux, without using live debugging with GDB, how to find a C program's state when it's hung?

We have an ancient network application (a client program running on one machine and a server program on another). 我们有一个古老的网络应用程序(一台机器上运行一个客户端程序,另一台机器上运行一个服务器程序)。 It usually works fine, but in rare cases it hangs. 它通常可以正常工作,但在极少数情况下会挂起。 We are yet to identify what exactly is causing the hang. 我们尚未确定到底是什么导致了挂起。 It's plain old socket programming written in C. 这是用C语言编写的普通套接字编程。

The problem is, we can't reproduce this, it just happens sometimes. 问题是,我们无法重现这一点,它有时会发生。

What can I do to find out the status of both server and client programs(code blocks where it's hung) when it hangs? 当服务器和客户端程序挂起时,我该怎么办才能查明它们的状态? Attaching to debugger is not possible for various reasons(the program immediately needs to be killed to release the blocked port). 由于各种原因,无法附加到调试器(程序必须立即被杀死以释放阻塞的端口)。

I just read about gcore, I will give it a try. 我刚刚读了有关gcore的文章,我将尝试一下。

Any better ideas? 还有更好的主意吗?

Update: gcore(or other ways to generate core dumps) worked perfectly fine. 更新:gcore(或其他生成核心转储的方式)运行良好。

Few I am familiar with 我很少熟悉

Tip Number 1 小费编号1

pstack

usage 用法

pstack <process Id>

for example 例如

below is the sample out for bash process with pid 3258 以下是使用pid 3258进行bash处理的示例

     PID TTY          TIME CMD
 3258 pts/6    00:00:00 bash
 3326 pts/6    00:00:00 ps


    pstack 3258
#0  0x0000003ab5eaa77e in waitpid () from /lib64/libc.so.6
#1  0x000000000043ebf2 in ?? ()
#2  0x000000000043fe4f in wait_for ()
#3  0x0000000000430a59 in execute_command_internal ()
#4  0x0000000000430c4e in execute_command ()
#5  0x000000000041d536 in reader_loop ()
#6  0x000000000041ccf9 in main ()

Tip Number 2 提示号码2

gdb attach <process id>

and then 接着

(gdb) info threads 

Quite helpful 很有帮助

there are few others mentioned earlier like gcore , netstat also helps in determining the state 前面提到的其他一些东西,例如gcore,netstat还可帮助确定状态

Sending abort signal to the process will also generate core dump which can be later analysed using gdb. 发送中止信号到进程还将生成核心转储,以后可以使用gdb对其进行分析。 Similar to gcore. 类似于gcore。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM