On Fri, Apr 16, 2010 at 12:04 AM, Jan Schampera <jan.schamp...@web.de>wrote:

> Clark J. Wang schrieb:
> > In C code I can use lockf(), flock(), semaphore and mutex for locking /
> > unlocking. Can bash provide some similar mechanisms?
> >
>
> For simple things, which don't need to be 1000% rocksolid, you can use
> atomic operations like mkdir or noclobbered redirection for mutex purposes.
>
> mkdir seems to be better but it's a bit strange for locking purpose. :)
And if the script crashes the dir will be left unlocked.

Accessing the file locking mechanisms of the kernel isn't possible so
> far, but Bash has a plugin framework.
>

This may be the best way for the job. Actually I'm writing a loadable
builtin command named `lockf' which internally uses lockf(3). If the script
crashes the file will be automatically closed/unlocked by the OS.

The only inconvenience is that I have to port/compile the code to every
platform I'm working on.

>
> Jan
>

Reply via email to