Listing PID of sleeping processes
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,pidIf we want to parse this, we need to remove the header:
ps h -eo s,pidNow 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-