1

Given a | b, i'd like to kill b when a is finished. b is an interactive process, which doesn't terminates when a is finished (fzf in my case), and the whole a | b is executed in a $() subshell.

So far what i come up with was

echo $({ sleep 5 & a=$!; { wait $a; kill $b; } } | { fzf & b=$!; })

sleep represents a, and fzf represents b, the result in the example is used by echo, but in my case, it'd be an argument for ssh. It seems, that $b is not the PID of fzf, it's empty. As far as i understand, this shouldn't be the case, since i've used {}, and not (), so it's not executed in a subshell.

  • Maybe start a|b in the background and use pgrep to poll for a, then pkill to kill b as soon as a is gone. – Jaleks Dec 10 '18 at 22:19
  • @Jaleks I can't start a|b in the background, as b requires user interaction. – lennoff Dec 10 '18 at 22:22
  • kk, sorry, thought It would be some GUI process, did not look up fzf. Maybe then start the killing process (with a time out at beginning) in background before executing a|b, e.g. (sleep 20; while pgrep myProcA; do sleep 1; done; pkill myProcB ) & – Jaleks Dec 10 '18 at 22:47
  • this probably should be a feature of fzf as it can react at the time of EOF on read of stdin; other methods would be way more complicated – thrig Dec 11 '18 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.