简体   繁体   English

调试 Linux 进程挂起,它运行的是哪个代码?

[英]Debugging Linux process hangs, which code is it running?

I have a process running on a very weak Linux embedded device, which could not run gdb / gdb server on itself.我有一个在非常弱的 Linux 嵌入式设备上运行的进程,它无法在自身上运行 gdb / gdb 服务器。 I let it provoking a function X from a shared library repeatedly (there are also some others process calling it at the same time with much less frequency), it usually hangs somewhere inside the shared library after 1 day or a half-day.我让它反复从共享库中引发 function X (还有其他一些进程同时调用它的频率要低得多),它通常在 1 天或半天后挂在共享库中的某个地方。 How do I debug:我该如何调试:

  • In case it blocked somewhere: which is the last line of code it ran?万一它在某处阻塞:它运行的最后一行代码是哪一行?
  • In case it stuck in an infinite loop: which lines of code it running?如果它陷入无限循环:它运行了哪些代码行?

What I tried:我尝试了什么:

  • I dig into the shared library and put a lot of syslog inside to check.我深入研究了共享库,并在里面放了很多 syslog 来检查。 However, with a very high amount of syslog being called constantly, my process now hangs every 2-5 minutes.但是,由于不断调用大量 syslog,我的进程现在每 2-5 分钟挂起一次。 I think syslog is blocked by UNIX socket?我认为系统日志被 UNIX 套接字阻止?

gdb comes with a program called gcore , which will generate a core file from the running process. gdb 带有一个名为gcore的程序,它将从正在运行的进程中生成一个核心文件。

Many systems nowadays disable core files by default ( ulimit -c in a shell will show 0).现在许多系统默认禁用核心文件(shell 中的ulimit -c将显示 0)。 Use the ulimit -c unlimited shell command, then run your process in the same shell (these limits are inherited from the parent process. If you start your process some other way than directly from the shell, you will need to find out how to set them there. eg, LimitCORE= in a systemd unit file).使用ULIMIT ulimit -c unlimited UNLIMITE shell命令,然后在同一Z2591C98B70119FE624898B1EE424B5E91Z(这些限制中的其他限制)(如果您从其他过程中)进行Z2591C98B70119FE624B1E 6.1198B11198B1ENES ONTH INDY LIMITS INDY LONS 18 YESENS MENT 8您的过程。它们在那里。例如, LimitCORE=在 systemd 单元文件中)。

Once your process gets into the bad state, run gcore on its process ID.一旦您的进程进入错误的 state,请在其进程 ID 上运行gcore You can then copy it to your workstation and load it into gdb ( gdb <executable> <core-file> ).然后,您可以将其复制到您的工作站并将其加载到 gdb ( gdb <executable> <core-file> )。 You can then view the stack trace and other state as of the moment the core dump was taken.然后,您可以在获取核心转储时查看堆栈跟踪和其他 state。

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

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