How to safely maintain a status file

Laszlo Nagy gandalf at shopzeus.com
Thu Jul 12 19:38:37 CEST 2012


> Sorry, but you are wrong. It's just one operation that boils down to
> "point name to a different inode". After the rename op the file name
> either points to a different inode or still to the old name in case of
> an error. The OS guarantees that all processes either see the first or
> second state (in other words: atomic).
>
> POSIX has no operation that actually deletes a file. It just has an
> unlink() syscall that removes an associated name from an inode. As soon
> as an inode has no names and is not references by a file descriptor, the
> file content and inode is removed by the operating system. rename() is
> more like a link() followed by an unlink() wrapped in a system wide
> global lock.
Then please help me understand this.

"Good" case:

process #1:  unlink(old status file)
process #1: rename(new status file)
process#2: open(new status file)
process#2: read(new status file)

"Bad" case:

process #1:  unlink(old status file)
process#2: open(???) -- there is no file on disk here, this system call 
returns with an error!
process #1: rename(new status file)

If it would be possible to rename + unlink in one step, then it would be 
okay. Can you please explain what am I missing?




More information about the Python-list mailing list