Some notes on locking.

flock (1) (2)

lockfile (1)

Do not put the PID inside the lock file.

mutt_dotlock (1)

lockfile_create (3)

maillock (1) lockfile-create lockfile-remove lockfile-touch lockfile-check

lockfile-create --use-pid -r 0 file ; echo $?

lockfile-remove file

if ! lockfile-create --use-pid -r 0 file ; then echo no lock ; else echo lock ; fi