diff options
author | Aaron LI <aly@aaronly.me> | 2018-02-05 14:15:08 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2018-02-05 14:15:08 +0800 |
commit | 9ba3e923040b6e1c4a5950d160aa62d42bf5bd87 (patch) | |
tree | ce70361d3264ceb74dcb2ca426bd1f6bb7291710 /unix/waiton.sh | |
parent | 75017f26eb6657130c48921a747e829d02c0a9c3 (diff) | |
download | atoolbox-9ba3e923040b6e1c4a5950d160aa62d42bf5bd87.tar.bz2 |
Add findpid.sh and waiton.sh tools
Diffstat (limited to 'unix/waiton.sh')
-rwxr-xr-x | unix/waiton.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/unix/waiton.sh b/unix/waiton.sh new file mode 100755 index 0000000..67d88ac --- /dev/null +++ b/unix/waiton.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# +# Wait for a UNIX process to finish +# Jon Cairns +# http://blog.joncairns.com/2013/03/wait-for-a-unix-process-to-finish/ +# 2013-03-20 +# + +case "$1" in + -h|--help|"") + echo "usage: ${0##*/} <pid>" >&2 + exit 1 + ;; +esac + +pid="$1" +me="${0##*/}($$)" +name=$(ps -p ${pid} -o comm=) +if [ $? -eq 0 ]; then + echo "${me}: waiting for process (${pid}, ${name}) to finish ..." + while ps -p ${pid} >/dev/null 2>&1; do + echo -n . + sleep 1 + done + echo +else + echo "${me}: failed to find process with PID ${pid}" >&2 + exit 2 +fi |