How can I detect hung processes in Linux using C?

c, linux

Solution

Under linux the way to do this is by examining the contents of /proc/[PID]/* a good one-stop location would be /proc/*/status. Its first two lines are:

Name: [program name] State: R (running)

Of course, detecting hung processes is an entirely separate issue.

/proc//stat is a more machine-readable format of the same info as /proc//status, and is, in fact, what the ps(1) command reads to produce its output.

Problem

Possible Duplicate: Linux API to list running processes? How can I detect hung processes in Linux using C?

Original source

Related problems