Ubuntu – List only processes that are in suspended mode

processpssuspend

to list processes that are running in the background, one can type:
ps -ef or ps -aux

but how to list processes that are suspended, let's say I had some process in the foreground and just suspended (either with bg <jobid> or Ctrl+z)

how to I get to know what are the processes in that status (suspended)?

thanks

Best Answer

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/'
Related Question