I have script which I assuming hangs sometimes.
My goal is wait till the script got completed or kill it if it didn't come up after 30 sec with some return code.
(function) & pid=$!
wait $pid || sleep 30 || kill -9 $pid
finished=$?
So I am thinking of above. I don't want to waste extra second sleeping if process finishes early that why I am using wait.
Is this correct or any better approach ?