Search code examples
linuxbashpid

best way to wait a particular pid


What is the best way to wait a particular pid from another shell (ie without a loop)

Actually I use this solution (doesn't work if root is the owner):

while kill -0 $pid > /dev/null 2>&1
do
   echo "waiting $pid"        
   sleep 10
done

Alternative (doesn't work with zombie processus)

while ps -p `cat $PID_FILE` > /dev/null 2>&1
do
    echo "waiting $pid" 
    sleep 10; 
done

Solution

  • I'm sad, apparently no solution without loop and no "event" API for process.

    My prefered solution is

    while [ -e /proc/$pid ]
    do
       echo "waiting $pid"        
       sleep 10
    done