aboutsummaryrefslogtreecommitdiffstats
path: root/unix/waiton.sh
blob: 988d3d32d067fb8d9d4215985ff09cca40c85454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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##*/} (pid=$$)"
name=$(ps -p ${pid} -o args=)
if [ $? -eq 0 ]; then
    echo "${me}: waiting for process (pid=${pid}, ${name}) to finish ..."
    while ps -p ${pid} >/dev/null 2>&1; do
        echo -n .
        sleep 3
    done
    echo
else
    echo "${me}: failed to find process with PID ${pid}" >&2
    exit 2
fi