[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Feature request: Can bash provide some mechanism for locking/unlock
Clark J. Wang
Re: Feature request: Can bash provide some mechanism for locking/unlocking?
Fri, 16 Apr 2010 09:31:15 +0800
On Fri, Apr 16, 2010 at 12:04 AM, Jan Schampera <address@hidden>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.
Re: Feature request: Can bash provide some mechanism for locking/unlocking?, Jan Schampera, 2010/04/15
- Re: Feature request: Can bash provide some mechanism for locking/unlocking?,
Clark J. Wang <=