Skip to content

Instantly share code, notes, and snippets.

@cslarsen
Created June 8, 2016 07:42
Show Gist options
  • Save cslarsen/f7a92694ed445e9e881c9fed73b87cdc to your computer and use it in GitHub Desktop.
Save cslarsen/f7a92694ed445e9e881c9fed73b87cdc to your computer and use it in GitHub Desktop.
BASH program that waits until given PIDs have terminated. Rename to pwait and chmod +x.
#!/bin/bash
if [ $# -eq 0 ]; then
echo "Usage: pwait <PID>"
echo "Waits until PID has terminated, then continues."
echo "Example: pwait 123 && echo DONE"
exit 1
fi
for pid in "$@"; do
while [ -e /proc/$pid ]; do
sleep 0.1
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment