Skip to content

Instantly share code, notes, and snippets.

@deostroll
Created December 14, 2017 04:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deostroll/931e417faa0e8eef5a504e74f2d2817c to your computer and use it in GitHub Desktop.
Save deostroll/931e417faa0e8eef5a504e74f2d2817c to your computer and use it in GitHub Desktop.
script to wait for a particular pid - bash
#!/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