List only processes that are in suspended mode
The output of ps
includes the status:
$ ps aux | head -n2
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 200892 5132 ? Ss Mar04 0:20 /sbin/init
The STAT
column is the state of the process. This can be one of (from man ps
):
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 by job control signal
t stopped by debugger during the tracing
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z defunct ("zombie") process, terminated but not reaped by its parent
So, you are looking for processes whose state is shown as T
. To see only those processes, you can parse the ps
output for them:
ps aux | awk '$8=="T"'
Sometimes, additional characters can be added to the state field (depending on the options you use), so this might be a safer approach:
ps aux | awk '$8~/T/'
You can use the bash jobs
builtin to see the status of jobs that are backgrounded or suspended e.g.
-
start and background one process; start and suspend a second with Ctrl+Z
$ sleep 100 & sleep 200 [1] 12444 ^Z [2]+ Stopped sleep 200
-
check the status of all jobs
$ jobs [1]- Running sleep 100 & [2]+ Stopped sleep 200
-
check the status of only suspended jobs
$ jobs -s [2]+ Stopped sleep 200
See the JOB CONTROL
section of man bash
, or the shell's online help help jobs
.