fuser

Anyone ever use fuser,
i tried this command fuser /database.bk
but it only returns datbase.bk:

I read some of the forums online, one of them said when he used fuser, it broke down the box, i really don't want that happen.

I thought fuser is to see who is accessing that file, right?
any help is greatly appreciated. i have been searching online, and there is not that much help on fuser.

thanks.

The command fuser is used to list processes using a file. If nothing is return, then the file is not use by anyone at that time. If the file is used, you will get the PID of users using the file:

 
unixbox:/ # fuser YOURFILE
YOURFILE:     8316o    5452o    2351o    5426o    1393o   26348o   24673o
8886o   28688o   16107o   18838o   11514o   29396o    3810o   15796o    

I don't see how fuser command could cause any problem to your system, maybe someone has an other opinion.

If running fuser causes a problem to occur, the system was broken before fuser was run. But I have never seen anything like that happen.

thanks for your reply. yes, you are right, no one was using that file.
yes, it is strange that fuser will bring down the system. don't think so either.

thanks.

Strange question, but.. how do you actually OPEN a file to test this behaivour ? I ask this because I tried with vi thefile but fuser shows another process different than the session where I actually executed vi thefile. Which leads me to think that probably vi open up a new version of the file to edit it.

Try:
sleep 5000 < somefile

Thanks Perderabo. And I was wrong, problem is that I was using echo $$ before I ran vi somefile, and obviously, the process invoked by 'vi somefile' is different than the one I was seeing from the terminal. I just needed to use ps to see the process vi actually used when fuser'ing the file. Great!

try lsof, I like it much more...

Hello ,

here under an interessant use of fuser with -u optioon ( see more on man :p)
its display the PID + USER of the process accessing the file :

fuser -u messages
messages: 230o(root)
ps -edf|grep 230|grep -v grep
root 230 1 0 Jan 15 ? 0:02 /usr/sbin/syslogd