仅列出处于挂起模式的进程

Alg*_*ina 12 suspend process ps

要列出在后台运行的进程,可以键入: ps -efps -aux

但是如何列出暂停的进程,假设我在前台有一些进程并且刚刚暂停(使用bg <jobid>Ctrl+z

我如何了解处于该状态(暂停)的进程是什么?

谢谢

ter*_*don 11

的输出ps包括状态:

$ 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
Run Code Online (Sandbox Code Playgroud)

STAT列是进程的状态。这可以是(来自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
Run Code Online (Sandbox Code Playgroud)

因此,您正在寻找状态显示为 的进程T。要仅查看这些进程,您可以解析ps它们的输出:

ps aux | awk '$8=="T"'
Run Code Online (Sandbox Code Playgroud)

有时,可以将其他字符添加到状态字段(取决于您使用的选项),因此这可能是一种更安全的方法:

ps aux | awk '$8~/T/'
Run Code Online (Sandbox Code Playgroud)


ste*_*ver 9

您可以使用jobs内置的 bash来查看后台或暂停的作业的状态,例如

请参阅JOB CONTROL部分man bash或 shell 的联机帮助help jobs