Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a process is in hang state (Linux) [closed]

Tags:

linux

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

like image 615
anil Avatar asked Sep 07 '10 13:09

anil


People also ask

How do you check if a process is killed in Linux?

To verify that the process has been killed, run the pidof command and you will not be able to view the PID. In the above example, the number 9 is the signal number for the SIGKILL signal.

How do I get Stacktrace on Linux?

In order to get a stack trace on Linux or Windows one must have either the GNU Debugger, gdb, or the LLVM Debugger, lldb, installed. Linux users should their package manager to install one or the other if necessary.


3 Answers

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

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):

  • 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
  • hung process was killed to give a chance for a monitoring application to restart the hung instance.

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".

like image 70
Dummy00001 Avatar answered Oct 17 '22 00:10

Dummy00001


you could check the files

/proc/[pid]/task/[thread ids]/status
like image 35
RRM Avatar answered Oct 17 '22 01:10

RRM


What do you mean by ‘hang state’? Typically, a process that is unresponsive and using 100% of a CPU is stuck in an endless loop. But there's no way to determine whether that has happened or whether the process might not eventually reach a loop exit state and carry on.

Desktop hang detectors just work by sending a message to the application's event loop and seeing if there's any response. If there's not for a certain amount of time they decide the app has ‘hung’... but it's entirely possible it was just doing something complicated and will come back to life in a moment once it's done. Anyhow, that's not something you can use for any arbitrary process.

like image 29
bobince Avatar answered Oct 16 '22 23:10

bobince