#!/bin/sh test -n "$PIDFILE" || { echo >&2 'Missing $PIDFILE env'; exit 1; } # run the program, and capture pid prog="$1"; shift "$prog" "$@" & pid=$! rc=$? # write pid to file echo "$pid" > "$PIDFILE" exit $rc