Curious situation with unlink() and open()

D. Hugh Redelmeier hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Tue May 1 04:03:40 UTC 2012


| From: William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>

| 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.

I don't really understand your problem and the consequent solution
space.

Why does one process want to create the file, lock it, write it, and
then delete it?  Why would that interfere with another process?  When
both are trying to operate on the same pathname, does that mean both
are actually trying to operate on the same entity, or is that just a
clash?  What should happen in that case, and why?

Here's a trick that may or may not be relevant to what you are trying
to do.  A process can create a file with a private / unique /
temporary name.  Once the content is finalized, the process can move
it to the desired name (i.e.  link(tempname, finalname);
unlink(tempname);).  The link is an atomic operation so often file
locking isn't needed.  Note: the link call will fail with EEXIST if
finalname already exists; this is a feature, not a bug.
--
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