M BUZZ CRAZE NEWS
// news

How to find sleeping process in Ubuntu?

By Emma Johnson

Is there any way to find sleeping processes in Ubuntu?

I can see top can list out number of sleeping processes, but I want them to be listed with their name.

Are there any commands for that?

4 Answers

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) and h 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 with ucmd 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.

1

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 state D or S.

Possible states are, from top(1):

 'D' = uninterruptible sleep 'R' = running 'S' = sleeping 'T' = traced or stopped 'Z' = zombie
2
ps -e S 

will show you sleeping processes.

3

Using awk and ps

ps o pid,state,command | \ awk ' {if ($2 == "T") {printf "%s\t%s\t%s\n","Sleeping",$1,$3};}'

Example

Start mc in a terminal, open a new terminal and start the commands below

kill -STOP $(pgrep mc)
ps o pid,state,command | \ awk ' {if ($2 == "T") {printf "%s\t%s\t%s\n","Sleeping",$1,$3};}'

Output is

Sleeping 21668 mc

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy