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

I guessed when I wrote Linux::Fuser and looked in /proc/*/fd and found all the file descriptors that had the same inode as the file I was interested in. Having just looked the source of fuser it appears it was a good guess ;-)

/J\

Replies are listed 'Best First'.
Re^3: How to detect if file is in use?
by thor (Priest) on Mar 17, 2005 at 12:45 UTC
    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

      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\

      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