[tpm] Renaming a file with multiple scripts having opened filehandles on it
Liam R E Quin
liam at holoweb.net
Fri Oct 2 18:45:16 PDT 2009
On Fri, 2009-10-02 at 20:44 -0400, Madison Kelly wrote:
> [...] I noticed that if a second program/thread
> had an open file handle on the log file being 'rename'ed, it would
> follow the log file to the new name. This makes sense, now that I think
> of it (I am guessing it tracks the inode?).
This is platform specific, but yes, on Unix-like systems, if you
rename a file, something writing to that file will continue to write
to it under the new name. On a Unix (and Linux) file system,
the directory entries (e.g. for "/etc/group" I mean the "group"
entry in the "/etc" directory) just point to where the data is
stored - this is why when you use "ln group fizz", there are
now two names for the same data, and if you remove either one,
the other remains behind. This is different from symbolic links,
ln -s, of course.
> What I want to do though is have some way for other threads recognize
> that the file name has changed.
You'd have to notify them, e.g. with a shared variable or a signal of
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org www.advogato.org
More information about the toronto-pm