Curious situation with unlink() and open()

William Park opengeometry-FFYn/CNdgSA at public.gmane.org
Tue May 1 03:22:12 UTC 2012


On Mon, Apr 30, 2012 at 10:36:50PM -0400, Yanni Chiu wrote:
> On 30/04/12 10:18 PM, William Park wrote:
> >
> >Hmm... creating separate lock file (O_RDONLY|O_CREAT|O_EXCL) seems to
> >work, by forcing open() to fail for all subsequent attempts to get fd.
> >It's polluting the directory, but the code is only few lines more.
> >Thanks.
> 
> So now the problem that could arise is that some process fails to remove 
> the lock file, due to some premature exit.

Perhaps, O_WRONLY|O_CREAT|O_EXCL instead and write pid in the file.  If
pid doesn't exist, or does exist but is different program, then it's
stale lock?

> 
> Is there standard (shell?) code for things like this? Or, is using an 
> RDB a quick and easy (but heavyweight) solution.

Now that you mention it... what I'm trying to do is to break up
GDBM-like database into one record per file.  Filename will be the
"key" to the record, and the file content will be record content.  What
those "record" is, is a little different issue.  In my case, it's
spreadsheet.
-- 
William
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list