I want to spawn two child processes, but wait until the first reaches a certain point in its execution (which can be determined by examining stdout) before spawning the second. I'm not sure which unix commands would be involved in accomplishing this, and have had a hard time finding anything via google due to the terse and sometimes cryptic nature of unix command names.
I'm not seeking a solution to the specific problem I'm trying to solve (although any additional pointers would be appreciated), I'm primarily concerned with knowing which unix commands I'd want to look up and learn to use.
Best Answer
You can use the
xargs
utility for this. It can run a command for each line on stdin, so we just need to ensure thatxargs
gets as input a single line on stdin at the time it should start the command, which can be accomplished withgrep
:The arguments
--max-count=1
,--max-lines=1
and--no-run-if-empty
ensure thatproc2
is started exactly once if and whenproc1
outputs${targetString}
for the first time, and never ifproc1
never outputs${targetString}
. The--replace
avoids thatxargs
appends the input line to its command line.I used the following command line to test it: