niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » Unix internals
unlink atomicity?
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
Alan J Rosenthal
*nix forums beginner


Joined: 14 May 2005
Posts: 1

PostPosted: Sat May 14, 2005 10:05 pm    Post subject: unlink atomicity? Reply with quote

I'm writing a little web thingy using the CGI interface. My program will
claim appointment times. I'm thinking of making the claiming of a time
be represented by the unlinking of a file, and there will be one file
(remaining) for each available time.

But unlike the properties we're used to for link() and creat(), I don't
know of any atomicity guarantees for unlink() (and TFM doesn't specify).
If two processes unlink() a file at about the same time, and not involving
NFS or anything nasty like that, is it guaranteed that exactly one of them
will succeed and the other will get ENOENT? Or is it possible for both of
them to get a zero return value? Even worse, is it possible for them both
to get ENOENT but the file is actually unlinked?

I could use another method to do my atomic operation (e.g. link() or creat()!),
but I need to unlink the file anyway, so it seems perfect as a synchronizer...
if there is the above atomicity guarantee.

This will actually run on linux at the moment, but I'm at least as interested
in the unix answer as well, in the unlikely case that they are different.
Or any information about which versions of unix have which behaviour, etc.
I'm imagining that it's atomic, in the absence of nasties such as NFS, but
I'm not going to rely on that unless I have some actual information to that
effect! I'd also want to know if the answer changes for multi-CPU systems.

thanks,
ajr
Back to top
Josip Gracin
*nix forums beginner


Joined: 20 Feb 2005
Posts: 42

PostPosted: Mon May 16, 2005 8:33 am    Post subject: Re: unlink atomicity? Reply with quote

On Sun, 15 May 2005 00:05:40 +0000, Alan J Rosenthal wrote:
Quote:
If two processes unlink() a file at about the same time, and not involving
NFS or anything nasty like that, is it guaranteed that exactly one of them
will succeed and the other will get ENOENT?

Based on what I see in Solaris 8 and Linux 2.6 source code, both systems
synchronize the unlink operation. Therefore, only one process will get
0 return value from unlink().
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Fri Jan 09, 2009 6:16 am | All times are GMT
navigation Forum index » Programming » Unix internals
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts why is perl -e 'unlink(glob("*"))' so much faster than rm ? elw Perl 14 Mon Jul 17, 2006 3:16 pm
No new posts Help with rename and unlink script please Dynamo PHP 4 Thu May 25, 2006 7:18 am
No new posts perlcc error - 'Can't unlink error file...' Paul Urbanus Perl 2 Fri Apr 07, 2006 2:13 pm
No new posts PHP/IIS: File Read/Write OK, File Unlink Denied lorenzogordon@hotmail.com PHP 10 Wed Mar 22, 2006 10:10 am
No new posts os.unlink() AND win32api.DeleteFile() rbt python 4 Tue Jan 24, 2006 2:56 am

Car Credit | Loans | Personal Loans | Keeping Aquarium Fish | Credit Card Advice
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1980s ][ Queries: 16 (0.1237s) ][ GZIP on - Debug on ]