I am new to Unix, Linux, and shell scripting.
I need to know how to find the number of running, sleeping, stopped, and zombie processes.
I think I found some ways to find the number of running processes:
ps -ef | wc -l
ps r | wc -l
But I'm not sure which is better, or if either is a good way to do this.
When it comes to sleeping, stopped, and zombie though, I have no clue where to go.
Any help would be appreciated.
Easy way, use
top
in one-shot mode:You can then use
awk
to pull out the individual numbers, if that's more palatable:If you happen to have a process named "zombie" this recipe will run afoul. You might want to replace
grep zombie
withsed -n 2p
.