Created
May 18, 2018 06:33
-
-
Save dipakc/a8bd104d265bd318fd45151e53a88937 to your computer and use it in GitHub Desktop.
Wait for a pid to finish
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 | |
| pid=$1 | |
| me="$(basename $0)($$):" | |
| if [ -z "$pid" ] | |
| then | |
| echo "$me a PID is required as an argument" >&2 | |
| exit 2 | |
| fi | |
| name=$(ps -p $pid -o comm=) | |
| if [ $? -eq 0 ] | |
| then | |
| echo "$me waiting for PID $pid to finish ($name)" | |
| while ps -p $pid > /dev/null; do sleep 5; done; | |
| else | |
| echo "$me failed to find process with PID $pid" >&2 | |
| exit 1 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment