Created
December 14, 2017 04:22
-
-
Save deostroll/931e417faa0e8eef5a504e74f2d2817c to your computer and use it in GitHub Desktop.
script to wait for a particular pid - bash
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)($$):" | |
echo "$me" | |
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 1; 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