Killing a process when some other process is finished

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












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.










share|improve this question





















  • 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 at 22:19










  • @Jaleks I can't start a|b in the background, as b requires user interaction.
    – lennoff
    Dec 10 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 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 at 15:16















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.










share|improve this question





















  • 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 at 22:19










  • @Jaleks I can't start a|b in the background, as b requires user interaction.
    – lennoff
    Dec 10 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 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 at 15:16













1












1








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.










share|improve this question













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.







shell-script pipe kill job-control






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 10 at 22:14









lennoff

61




61











  • 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 at 22:19










  • @Jaleks I can't start a|b in the background, as b requires user interaction.
    – lennoff
    Dec 10 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 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 at 15:16
















  • 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 at 22:19










  • @Jaleks I can't start a|b in the background, as b requires user interaction.
    – lennoff
    Dec 10 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 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 at 15:16















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 at 22:19




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 at 22:19












@Jaleks I can't start a|b in the background, as b requires user interaction.
– lennoff
Dec 10 at 22:22




@Jaleks I can't start a|b in the background, as b requires user interaction.
– lennoff
Dec 10 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 at 22:47




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 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 at 15:16




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 at 15:16















active

oldest

votes











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487223%2fkilling-a-process-when-some-other-process-is-finished%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487223%2fkilling-a-process-when-some-other-process-is-finished%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay