#!/bin/sh
if mkdir /your/lockdir
then trap "rmdir /your/lockdir" EXIT INT ABRT TERM
...code goes here...
else echo somebody else has the lock
fi
No matter how many processes attempt to make the directory, only one will succeed. That works for my scripting, but I have never used it in C.was just wondering, could something else remove the dir in between the if and then, before trap?
Just wondering about the atomicity.
With this one, it was "Wow, $foo was a simpler problem than I thought and Unix (and thus Linux and OSX) just totally screwed it up for no reason"
You know things are bad when the least awful implementation of OS-level locking is the one from Microsoft.