Skip to content

Instantly share code, notes, and snippets.

@jvmvik
Last active June 13, 2016 22:38
Show Gist options
  • Select an option

  • Save jvmvik/3404029da0fc5ac616eda2abfd7f1e36 to your computer and use it in GitHub Desktop.

Select an option

Save jvmvik/3404029da0fc5ac616eda2abfd7f1e36 to your computer and use it in GitHub Desktop.
Launch a process on the background, then start a loop waiting for the process completion.
#!/bin/bash
cmd="sleep 5s"
# Run a command
nohup $cmd > /dev/null 2>&1 &
pid=$!
# Here is the process id
echo $pid
# Wait for the process to finish
while true ;
do
ps -p $pid > /dev/null
if [[ $? == 0 ]];
then
echo "Waiting..."
sleep 2s
else
# Exiting
break;
fi
done
echo "Bye bye..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment