[Gllug] Single instance of a process - simple way

Tethys sta296 at astradyne.co.uk
Fri Jul 6 07:45:21 UTC 2007


--------

Henrik Bilar writes:

>You can use (file system) links to achieve locking, as the creation of a
>lock is atomic. I wrote a little shell script wrapper for this once,
>http://www.bilar.co.uk/wiki/index.php/Lock_manager_in_Bash

It's racy, though. Two processes trying to set the same lock at the
same time could interfere with each other, such that one process could
believe it has the lock, yet it contains the PID of the other processes.
Try using mktemp(1) to make the temporary lock instead.

ObRant: Don't shout with your variable names unless they're environment
variables. Quote your variables when you deference them, particularly
given that some of them have user supplied input.

Tet
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list