How to find sleeping process in Ubuntu?
Solution 1:
Try this:
ps o state,command axh | grep "^[SD]" | cut -b 3-
for listing commands of processes with an interruptable and uninterruptable sleep state.
-
ps
outputting only state and commands of all processes (ax
) andh
removes the header line. -
grep
filters processes other than the two sleep states -
cut
is used to remove the state output again. - Optionally replace
command
withucmd
if you don't need the full name including all arguments.
This is probably suboptimal scripting here, but I couldn't find a quick way to have ps
filtered for a specific state.
Solution 2:
You could grab the information from top, which can be run in batch mode (-b
).
top -bn1 | awk 'NR > 7 && $8 ~ /S|D/ { print $12 }'
-
-n1
top runs only once and exits. -
NR > 7
skips header. -
$8 ~ /S|D/
selects programs which are in stateD
orS
.
Possible states are, from top(1)
:
'D' = uninterruptible sleep 'R' = running 'S' = sleeping 'T' = traced or stopped 'Z' = zombie