Alg*_*ina 12 suspend process ps
要列出在后台运行的进程,可以键入:
ps -ef
或ps -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)
您可以使用jobs
内置的 bash来查看后台或暂停的作业的状态,例如
启动和后台一个进程;用Ctrl+开始和暂停一秒钟Z
$ sleep 100 & sleep 200
[1] 12444
^Z
[2]+ Stopped sleep 200
Run Code Online (Sandbox Code Playgroud)检查所有作业的状态
$ jobs
[1]- Running sleep 100 &
[2]+ Stopped sleep 200
Run Code Online (Sandbox Code Playgroud)检查仅暂停作业的状态
$ jobs -s
[2]+ Stopped sleep 200
Run Code Online (Sandbox Code Playgroud)请参阅JOB CONTROL
部分man bash
或 shell 的联机帮助help jobs
。