Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

Listing PID of sleeping processes

Writer Sebastian Wright

I've been reading about processes for a few hours now and I've got a question I'm not able to answer.

How can I display the PID of sleeping processes and also determine and list their number ?

2 Answers

Yes. You can use the ps tool to list all processes and their state:

ps -eo s,pid

If we want to parse this, we need to remove the header:

ps h -eo s,pid

Now we are going to pipe it to an awk command so that we can only print the pids with a state of "S" (sleeping):

ps h -eo s,pid | awk '{ if ($1 == "S" || $1 == "D") { print $2 } }'

And now you have a newline separated list of process IDs that are sleeping.

Do with it what you wish.

I normally use this commend

ps o state,command axh | grep "^[SD]" | cut -b 3-

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