What exactly is happening here?
root@bob-p7-1298c:/# ls -l /tmp/report.csv && lsof | grep "report.csv"
-rw-r--r-- 1 mysql mysql 1430 Dec 4 12:34 /tmp/report.csv
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
Best Answer
FUSE and its access rights
lsof
by default checks all mounted file systems including FUSE - file systems implemented in user space which have special access rights in Linux.As you can see in this answer on Ask Ubuntu a mounted GVFS file system (special case of FUSE) is normally accessible only to the user which mounted it (the owner of
gvfsd-fuse
). Evenroot
cannot access it. To override this restriction it is possible to use mount optionsallow_root
andallow_other
. The option must be also enabled in the FUSE daemon which is described for example in this answer ...but in your case you do not need to (and should not) change the access rights.Excluding file systems from lsof
In your case
lsof
does not need to check the GVFS file systems so you can exclude thestat()
calls on them using the-e
option (or you can just ignore the waring):Checking certain files by lsof
You are using
lsof
to get information about all processes running on your system and only then you filter the complete output usinggrep
. If you want to check just certain files and the related processes use the-f
option without a value directly following it then specify a list of files after the "end of options" separator--
. This will be considerably faster.General solution
To exclude all mounted file systems on which
stat()
fails you can run something like this (inbash
):Or to be sure to use
stat()
(test -e
could be implemented a different way):