如何列出在bash所有背景的PID [英] How to list all background pids in bash
问题描述
要么我不能够正确短语我的搜索或答案不容易找到!但我试图找出如何列出我所有的后台任务的PID。例如:
Either I am not able to phrase my search correctly or the answer is not easy to find!, but I am trying to figure out how to list all of my background task PIDs. For example:
到目前为止,我已经发现,列出我们使用的最后一个PID:
So far I have found that to list the last PID we use:
$!
但现在我想列出之前任务的PID(如果存在的话),但我找不到如何做到这一点。 Utlimatly我想列出所有的后台任务的PID。
But now I want to list the PID of the task before that (if one exists), but I can't find how to do that. Utlimatly I want to list all my background task PIDs.
我知道我们还可以找到与去年作业ID:
I know we can also find last job ID with:
%% (last job in list)
%1 (first job in list)
%2 (second job in list)
但同样似乎并不进程ID工作?
But the same does not seem to work for process id?
感谢所有:)
推荐答案
使用 PS小号
。例如:
$ vim &
[1] 8263
$ ipython &
[2] 8264
$ ps S
PID TTY STAT TIME COMMAND
3082 pts/0 Ss 0:00 bash
3137 pts/0 Sl+ 0:00 python /usr/bin/ipython
8207 pts/2 Ss 0:00 bash
8263 pts/2 T 0:00 vim
8264 pts/2 Tl 0:00 python /usr/bin/ipython
8284 pts/2 Tl 0:00 python /usr/bin/ipython
8355 pts/2 R+ 0:00 ps S
如果你想获得的PID以下用途:
If you want get PIDs use below:
$ ps S | awk '{print $ 1 }' | grep -E '[0-9]'
3082
3137
8207
8263
8264
8284
8357
8358
835
您也可以使用工作-l
但只显示当前会话的后台进程。
Also you can use jobs -l
But it show background processes only for current session.
这篇关于如何列出在bash所有背景的PID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!