#!/bin/sh
#
# $Id: waitpid,v 1.2 1997/09/28 03:45:18 ejb Exp $
# $Source: /home/ejb/scripts/RCS/waitpid,v $
# $Author: ejb $
#

whoami=`basename $0`
if [ $# != 1 ]; then
   echo "Usage: $whoami pid" 1>&2
   echo "  waits for pid to exit" 1>&2
   exit 2
fi

pid=$1

# Use procfs if possible; this allows waitpid to be used on a process that
# the caller does not own.
procfs=0
if test -d /proc/$$/.; then
  procfs=1
fi
while test 1; do
  if test $procfs = 1; then
    test -d /proc/$pid || exit 0
  else
    (kill -0 $pid >/dev/null 2>&1) || exit 0
  fi
  sleep 1
done
