Ps
gives a similar description of process states
PROCESS STATE CODES
Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will
display to describe the state of a process:
D uninterruptible sleep (usually IO)
R running or runnable (on run queue)
S interruptible sleep (waiting for an event to complete)
T stopped, either by a job control signal or because it is being traced
Z defunct ("zombie") process, terminated but not reaped by its parent
(I skipped the obsolete ones)
ps -ax -o state,wchan,cmd,pid | tail -n+1| sort |less
should give you a nice snapshot of your processes, sorted by state.
The wchan
field shows the waiting channel, which specifies the state
of a process more closely.
If you do:
ps -o state,wchan,cmd,pid | tail -n+1| sort |less
it'll show the same info but just for the processes in your terminal session.
You can start different processes in the background of your current terminal session and check out what state they're in and what channel they're waiting on:
#this will be waiting on a timer (S hrtime)
sleep 200 &
touch file
#this will get the file lock to `file`, start start sleep and will be waiting on it to complete (S wait)
flock file -c "sleep 100" &
#this won't start sleep because it will be waiting on the file lock (S flock)
flock file -c "sleep 100" &
#ps will be running and the other guys will be waiting o pipe_w
ps -o state,wchan,cmd,pid | tail -n+1| sort |less
Processes that aren't technically waiting on a resource will internally be runnable, but they will still show up as being in the S
state (=waiting on the scheduler to put them on a processor core).
You'll only have a few really "running" processes and the number will be limited by the number of CPU cores you've got.
top
itself, so it wasn't regarded as a helpful distinction to make. Even now you would only have one per CPU or one per core/hyperthread. – Random832 May 22 '15 at 12:52D
, not all of them do: e.g.select(2)
puts the process toS
state until the condition waited is satisfied. – Ruslan May 22 '15 at 15:07