How to list all background values ​​in bash

Either I cannot correctly tell about my search, or it is not easy to find the answer, but I am trying to figure out how to list all my PID objects of the background task. For example:

So far, I have found that to list the last PID that we use:

$!

But now I want to specify the PID of the task before this (if it exists), but I can not find how to do it. Ulimitly I want to list all my PIDs of the source tasks.

I know that we can also find the last job id with:

%% (last job in list)
%1 (first job in list)
%2 (second job in list)

But does the same not seem to work for the process id?

Thanks everyone :)

+3
source share
4 answers

ps S. :

$ 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 :

$ ps S | awk '{print  $  1 }' | grep -E '[0-9]'
3082
3137
8207
8263
8264
8284
8357
8358
835

jobs -l .

+8

, , ?

jobs -l -p. -l -p , jobs .

+5

bash, tcsh, , , , , - jobs -l ( Long).

[ghoti@pc ~]$ sleep 300 &
[1] 33811
[ghoti@pc ~]$ sleep 301 &
[2] 33812
[ghoti@pc ~]$ sleep 302 &
[3] 33813
[ghoti@pc ~]$ jobs -l
[1]- 33811 Running                 sleep 300 &
[2]- 33812 Running                 sleep 301 &
[3]+ 33813 Running                 sleep 302 &
[ghoti@pc ~]$ 
+1

, (, disown ), , , :

grep "PPid:.*$$" /proc/[0-9]*/status | cut -d/ -f3

ps --ppid $$

may be helpful. (Credits @ Michael Ghazaryan, who also has the answer here.)

+1
source

Source: https://habr.com/ru/post/1618045/


All Articles