in reply to Re^2: How to detect if file is in use?
in thread How to detect if file is in use?

Is this a proper assumption? From what I know, inodes are unique based on filesystem, not on a system-wide basis. That is to say that you could have two file systems with two different files that have the same inode number.

thor

Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come

Replies are listed 'Best First'.
Re^4: How to detect if file is in use?
by gellyfish (Monsignor) on Mar 17, 2005 at 13:13 UTC

    Yes you are correct and I over-simplified, Linux::Fuser indeed does compare the device numbers of the file as well as the inode number:

    if (my @statinfo = stat $fd) { if (($dev == $statinfo[0]) && ($ino == $statinfo[1]) ) {
    You had me worried there for a second ;-)

    /J\

Re^4: How to detect if file is in use?
by betterworld (Curate) on Mar 17, 2005 at 12:59 UTC
    I don't think gellyfish said anything about inodes.
    If you look into /proc/*/fd/, you will find symlinks to all the files opened by the programs. By using readlink(), you can find out the path of those files (not the inodes).
      Different paths do not imply different files. You can have a million symlinks that point to the same underlying file.

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        There is also the possibility that the file was opened by a link that was subsequently removed.

        /J\

        It appears that the links in /proc/*/fd are canonified, i.e. if you open a symlink to foo, then /proc/$$/fd/xx will also point to foo:
        $ perl -le 'symlink("foo","bar") o r die $!; open F, ">bar" or die $!; print readlink("/proc/$$/fd/".file +no(F))' /tmp/foo
        Therefore, you can be sure that the paths in the proc filesystem aren't symlinks. Hard links are a harder problem. fuser seems to always get it right, though.