My Bash 4 script calls a third-party program P (one that I can't recompile), which prints warnings to STDOUT. When it prints yikes, it also enters an infinite loop. So when I detect a yikes, how can I immediately stop P and return control to my script? (And let P finish normally otherwise.)
Possibly useful fragments:
(echo $BASHPID > /tmp/subpid; ./P | tee /tmp/Pout ) &
tail -f /tmp/Pout | grep -m1 yikes && kill -9 $(cat /tmp/subpid)
wait