Reputation: 621
I need to execute node
and firefox
in that order. The node process needs to remain in the background until I close firefox manually.
I've tried this command:
node & nodePID=$! && firefox && pkill $nodePID
but $nodePID
seems to return pid of firefox instead of node. How would I fix this?
Note that I can't just pkill node
since I might have different node processes running at the same time.
Upvotes: 0
Views: 79
Reputation: 14424
Consider using kill $nodePID
instead of pkill ...
.
Also you want NOT to chain the commands with '&&'. For example, if firefox fail to launch, you still probably want to cleanup the node process. The assignment (nodePID=...) will never fail.
node &
nodePID=$!
firefox
kill $nodePID
Upvotes: 1