Reputation: 678
I sometimes launch long running tasks on my server and want the server to do something after those tasks finish (usually shut down). If there was only one task, I could simply type the next command into the window running the task, then bash will run it after the current one finishes. But what if there was multiple processes that I want to wait on?
In my workflow, the different tasks are running in different panes on tmux, so I cannot directly use wait
since the processes I want to wait for are not child processes in one particular pane.
I have included a possible approach as an answer below.
Upvotes: 0
Views: 38
Reputation: 678
This question's answer offers a related solution:
tail --pid=$pid -f /dev/null
However, that particular answer can only handle waiting for one process, but we can extend it using wait for multiple processes, then run our own command on completion:
tail --pid=$pid1 -f /dev/null &
tail --pid=$pid2 -f /dev/null &
tail --pid=$pid3 -f /dev/null &
tail --pid=$pid4 -f /dev/null &
wait; <your-command-here>
Upvotes: 1