| # Kill the pid referenced by a pidfile, if any. |
| log "Usage: $progname [-s signal] <pidfile>" |
| while getopts "hs:" option |
| # the rest are non-option arguments |
| if [ -z "$pidfile" ]; then |
| [ -e "$pidfile" ] || exit 0 |
| read pid junk <"$pidfile" |
| [ -n "$pid" ] || die "'$pidfile' exists but has no pid inside" |
| [ "$pid" -gt 1 ] || die "'$pidfile' pid is '$pid'; must be > 1" |
| if [ -n "$signal" ]; then |
| kill -"$signal" "$pid" 2>/dev/null |
| # By default, kill the process |
| kill -15 "$pid" 2>/dev/null |
| kill -0 "$pid" 2>/dev/null || break |
| kill -9 "$pid" 2>/dev/null |
| # return an error if the process *does* exist |
| ! kill -0 "$pid" 2>/dev/null |