Using temporary files
- use traps to clean up the system after exit
Useful signals are:
0 = ?? (FIXME)
1 = HUP
2 = INT
3 = QUIT
15 = TERM
- be sure not to use the same temporary file if two instances of the same program are running
- use mktemp or
- use the pid of the program $$
#!/bin/sh
lockfile=/var/lock/foo.lock
tempfile=/tmp/foo-$$
#handle command line arguments here
if [ -f $lockfile ]; then
exit 0;
fi
trap "rm -f $lockfile $tempfile" 0 1 2 3 15
touch $lockfile $tempfile || exit 1
#user program here