10

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

10

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/'
8

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.

1
  • Unfortunately jobs lists only those processes started in the current shell (i.e., on the command line) so doesn't pick up any that were started by the system or login process, etc. – Tom Russell Sep 19 '20 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.