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 8080is 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.cmd1 | cmd2is 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.