For example, I run
sleep 1 | sleep 2 | sleep 3 &
How do I get process ids of each part? I could examine output of jobs -l
but its format may wary among shells and I am looking for a simpler way.
For example, I run
sleep 1 | sleep 2 | sleep 3 &
How do I get process ids of each part? I could examine output of jobs -l
but its format may wary among shells and I am looking for a simpler way.
You can use pgrep
with -a
option for a full listing:
pgrep -a sleep
sleep
s started here from the PIDs of any other sleep
running simultaneously? How would you generalise this to a real solution for whatever the OP is actually trying to do (which probably doesn’t involve sleep
)?
– Stephen Kitt
Mar 18 '20 at 14:30
ps -ef|grep 'sleep '
– lainatnavi Mar 18 '20 at 14:21ps --ppid $$
– Panki Mar 18 '20 at 14:31pgrep -g
). If they're in the background, as in your example, you can grab them by$!
(but notice that$!
is not necessarily the session leader). Example:sleep 1 | sleep 2 | sleep 3 & pgrep -ag $(ps -ho pgrp $!)
. – Mar 18 '20 at 19:59/proc/PID/
files, without having to fight withps
,pgrep
and their limitations. – Mar 19 '20 at 15:22