如何检查进程是否处于挂起状态(Linux) [英] How to check if a process is in hang state (Linux)

查看:1474
本文介绍了如何检查进程是否处于挂起状态(Linux)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux中是否有任何命令可以通过该命令知道进程是否处于挂起状态.

Is there any command in Linux through which i can know if the process is in hang state.

推荐答案

Linux中是否有任何命令可以通过该命令知道进程是否处于挂起状态.

Is there any command in Linux through which i can know if the process is in hang state.

没有命令,但是一旦我不得不做一个非常愚蠢的破解来完成类似的事情.我编写了一个Perl脚本,该脚本定期(以我为例,每30秒一次):

There is no command, but once I had to do a very dumb hack to accomplish something similar. I wrote a Perl script which periodically (every 30 seconds in my case):

  • 运行ps来查找受监视进程的PID列表(以及执行时间等)
  • 在PID上循环
  • 使用其PID启动gdb附加到进程,使用thread apply all where从其转储堆栈跟踪,从进程中分离
  • 在以下情况下,一个进程被宣告挂起:
    • 它的堆栈跟踪没有变化,经过3次检查后时间也没有变化
    • 它的堆栈跟踪没有变化,经过3次检查,时间表明CPU负载为100%
    • run ps to find list of PIDs of the watched processes (along with exec time, etc)
    • loop over the PIDs
    • start gdb attaching to the process using its PID, dumping stack trace from it using thread apply all where, detaching from the process
    • a process was declared hung if:
      • its stack trace didn't change and time didn't change after 3 checks
      • its stack trace didn't change and time was indicating 100% CPU load after 3 checks

      但这是非常非常非常原始的骇客,它的目的是达到一个几乎不可错过的截止日期,几天后,在为该错误应用程序最终安装了修复程序之后,将其删除.

      But that was very very very very crude hack, done to reach an about-to-be-missed deadline and it was removed a few days later, after a fix for the buggy application was finally installed.

      否则,正如所有其他响应者绝对正确地指出的那样,没有办法确定进程是否挂起:仅仅是因为挂起可能是出于多种原因而发生,通常与应用程序逻辑相关联.

      Otherwise, as all other responders absolutely correctly commented, there is no way to find whether the process hung or not: simply because the hang might occur for way to many reasons, often bound to the application logic.

      唯一的方法是使应用程序本身能够指示它是否处于活动状态.最简单的方法可能是例如定期日志消息我还活着".

      The only way is for application itself being capable of indicating whether it is alive or not. Simplest way might be for example a periodic log message "I'm alive".

      这篇关于如何检查进程是否处于挂起状态(Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆