Skip to content

waitfor.8

Manvendra Bhangui edited this page Jul 12, 2026 · 1 revision

NAME

waitfor - wait for unrelated process

SYNOPSYS

waitfor [-v] pid

DESCRIPTION

waitfor(1) waits for an unrelated process using pidfd_open(2) on Linux, kqueue(2) on OpenBSD, FreeBSD, stat(2) and usleep(3) in a loop on Solaris, kill(2) and usleep in a loop for rest. It waits for the process to terminate before it exits with 0 return status. If there is an error waiting for the process, it exits 1. It can be used in supervise(8) run script to monitor a process started outside supervise, restarting it if needed. This can be important if the manually started application cannot be terminated if the downtime has a cost to business.

This example below starts up jboss under supervise after a clueless
application support person starts up jboss manually using the nohup
command.

#!/bin/sh
#
# supervise run script for jboss
#
exec 2>&1

# wait for manually started jboss application to terminate

pid=$(pgrep -f "java.*standalone.sh")
[ -n "$pid" ] && waitfor $pid

[ -x /usr/bin/svalert ] && /usr/bin/svalert "$@"
echo "Starting jboss"
exec setuidgid -es jboss /opt/jboss/bin/standalone.sh -b 0.0.0.0

SEE ALSO

pidfd_open(2) pidof(1) pgrep(1) pidwait(1)

Clone this wiki locally