If, in bash
, I execute:
cmd1 | cmd2 | ... | cmdi | ... | cmdn &
where the cmd{1..n}
may not be distinct, how do I get the PID of cmdi
? Alternatively, how can I signal the cmdi
process? (For example, send it SIGUSR1
?)
pkill
/pgrep
, pidof
etc. don't look like good answers, since other instances of cmdi
maybe running, including as part of the same pipeline. jobs -p
gives the PID of cmd1
, for me.
i
can be anything in {1..n}
.
cat /var/run/out | nc -l 8080
is only superficially similar tocmd1 | cmd2
? Your constraint, that you want to type the bare-bones pipeline *and then* recover the PIDs, is (1) not stated in the question, and (2) unlikely to allow for a good, general solution. – G-Man Says 'Reinstate Monica' Sep 18 '14 at 19:43cmd1 | cmd2
is a very special case where both PIDs are easily obtainable. Did I say anything about n? So why would you assume n=2? Did I say anything about what cmdi is? So why would you assume I could modify cmdi? I am asking for a general solution and you are imposing restrictions. – muru Sep 18 '14 at 19:48