How can I wait for PID to finish in another shell

Have a need to schedule programs that can run after other programs are completed. Here's the catch:

1) The list of programs will not always be the same (kind of a plug-n-play deal)
2) The invoking shell may not be the same as the shell of the program being waited on

In other words, I need to be able to wait on PID's from other shells in the same Unix box. I've looked through Unix in a Nutshell & Power Tools and found nothing.

Any advice?

Just loop checking to see if the process is still running. If so, sleep for ten seconds and loop again. If not continue.

This is a script I wrote a long time ago and have been using since (not sure how widespread pgrep is, but this works in Solaris).

#!/bin/bash

# Variables
PROCESS=""      # This is what you want to page on
MAILTO=""         # Space delmited list of email addresses
HOSTNAME=`hostname`
A=1

 # Processing
until [ ${A} -eq 2 ]; do
   pgrep -f "${PROCESS}" >/dev/null 2>&1
   if [ $? -eq 0 ]; then
        sleep 300
        else sleep 30
        pgrep -f "${PROCESS}" >/dev/null 2>&1
        FLAG=$?
        if [ ${FLAG} ! -eq 0 ]
           then echo "$PROCESS is no longer running on ${HOSTNAME}" | mailx -s "
${PROCESS}" ${MAILTO}
           A=2
           exit 0
        fi
   fi
done

It checks that a process is running every 5 minutes. If it goes away, it waits 30 seconds and checks one last time to make sure.

I know this isn't exactly what you are looking for, but you should be able to modify it to work (sorry, I have been at work too long today to do it).