[clug-talk] file locking in bash?
Robert Lewko
lewkor at gmail.com
Fri Jul 27 13:23:37 PDT 2007
On 7/27/07, Roy Souther <roy at silicontao.com> wrote:
>
> I have no man pages for flock.
>
As far as I could tell its a RedHat specific utiltiy. It would be about 2
hr to program.
To program this:
1) use the first argument as a lock file
2) you can use open with the o_CREAT
3) if this fails the file is already there - use open with O_RDONLY
4) use flock() with LOCK_EX to get an exclusive lock - if this call fails
then exit with error code
5) use one of the exec functions (without reading the man pages I can't
remember which one) to execute the remaining command line args in a new
process
The return value of the new process will become the return value for this
program. Call it flock.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://clug.ca/pipermail/clug-talk_clug.ca/attachments/20070727/4acfa068/attachment.html
More information about the clug-talk
mailing list