Last active
June 13, 2016 22:38
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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