[1685319 views]

[]

Odi's astoundingly incomplete notes

New entries | Code

PID file in bash

To write the PID of a background process to file:
/usr/bin/program &
echo $! > program.pid
To later check if the process is still running:
PID=$(cat program.pid)
if [ -e /proc/${PID} -a /proc/${PID}/exe -ef /usr/bin/program ]; then
echo "Still running"
fi


posted on 2006-04-21 21:30 UTC in Code | 2 comments | permalink
Spectacular! I used this to ensure my rsync script only runs one rsync at a time.

`rsync -avpogtH --links --copy-unsafe-links user@remotehost:/remote/directory/ /Local/HD/ >> $logfile.`& echo $! > program.pid
waitpid=`cat program.pid`
wait $waitpid

...and repeat
thanks!

Pol