[Gllug] Single instance of a process - simple way

Nix nix at esperi.org.uk
Fri Jul 6 23:05:40 UTC 2007


On 6 Jul 2007, Tethys spake thusly:
> 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.

I'm fairly sure file creation is not atomic on NFSv2. Using rename()
should always be safe.

-- 
`... in the sense that dragons logically follow evolution so they would
 be able to wield metal.' --- Kenneth Eng's colourless green ideas sleep
 furiously
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list