I'm developing a C++ application with process monitoring capabilities, which monitors state changes based on this model: http://www.macdesign.net/capella/it4813/images/stallings-Linux_process-thread_states-f4.18.png
However, as /proc/pid/status combines both the "ready" and "executing" states into "running", I'm at a loss as to how I can find out which of these states a process is actually in. Can anyone offer any suggestions as to how I may discover this?
The question is malformed. On a single CPU, it's literally never possible to see a process in the "running" state, because by definition the monitoring process has the CPU. If you really need fine-grained logging control over process transitions, you need to do it in the kernel (or at least with in-kernel support -- see lttng or systemtap for tools that might help here). Tools for tracking CPU usage from userspace are more coarse-grained, either using the total usage numbers already tracked by the kernel (e.g. /usr/bin/time
) or by sampling the process table at intervals (bootchart works this way).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With