Skip to content

Instantly share code, notes, and snippets.

@dipakc
Created May 18, 2018 06:33
Show Gist options
  • Select an option

  • Save dipakc/a8bd104d265bd318fd45151e53a88937 to your computer and use it in GitHub Desktop.

Select an option

Save dipakc/a8bd104d265bd318fd45151e53a88937 to your computer and use it in GitHub Desktop.
Wait for a pid to finish
#!/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