I have two programs server
and client
. server
terminates after an unknown duration. I want to run client
in parallel to server
(both from the same Bash script) and terminate client
automatically a few seconds after the server
has terminated (on its own).
How can achieve this?
I can run multiple programs in parallel from a bash script and timeout a command in Bash without unnecessary delay, but I don’t know the execution duration of server beforehand so I can’t simply define a timeout for client. The script should continue running so exiting the script to kill the child processes is not an option.
Edits
This question only addresses waiting for both processes to terminate naturally, not how to kill the client
process once the server
process has terminated.
@tripleee pointed to this question on Unix SE in the comments, which works especially if the order of termination is irrelevant.