Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


We are using an NFS share to allow clients to upload raw video material. The files are then polled from the directory on the (NFS) server in order to be processed. Since we do not want to process files which have not finished uploading yet, I want to determine in the server-side script (Bash), if the file is still in use.

As the man pages say, both fuser and lsof -N shall allow for detecting in-use files on NFS shares. However, I do not "see" the files as in use on the server which results in corrupt files later in the processing.


My NFS /etc/exports contains these settings (UID and GID being the owner of the shared directory on the server, line wrapped for better display):


The client mounts this share using:  /data002/  nfs  defaults        0 0

The server is a Ubuntu 10.04 using "nfs-kernel-server 1:1.2.0-4ubuntu4", the client is an SLES 10 SP2

When I open a file on the client (inside the shared directory), using

echo "Hello" > test.txt && tail -f foo.txt

and then check (still on the client) if the file is in use

fuser foo.txt

I can see that the file is in use. However, when checking on the server side (both fuser foo.txt and lsof -N | grep foo.txt) I do not get any usage information.

How can I check on the server if a file on the NFS share is currently in use (regardless if locally or remote)? Or what am I doing wrong in my current setup?

share|improve this question
up vote 4 down vote accepted

lsof will only show you which resources are being used by your local system, in no case it'll show any foreign resource acquisition, but there's a way around that...

All remote usage will be tracked by the lockd daemon on the NFS server and it'll issue a lock on the file if you try to access it while being written by another node, so if you're using this (your mount options kinda point that way) you can in that case use lsof to show if a file is locked.

share|improve this answer
lynxman, thanks for your comment. I read about file locks on NFS in another thread[0] in a PHP context. How can this be used from a shell? I saw "flock" when looking at apropos lock, but this is just a function not a command/shell builtin. [0] EDIT: Okay, flock is available in my bash, but it can be used to acquire/release locks on files, not check if there are any. – Axel Knauf Jan 19 '11 at 10:24
Well there's no easy way around it, lsof should show you the locking and if it doesn't (which can happen with NFS) just go ahead and write a small program to lock and unlock a file quickly to see if it's locked – lynxman Jan 20 '11 at 8:35
Thanks for your suggestions. I now use a cronjob ob the client, where I can see access to the file(s) using fuser to check if it is in use. If it is not, I move it to another folder (on the share) which is fast. – Axel Knauf Jan 20 '11 at 11:07
Glad to see it worked! – lynxman Jan 20 '11 at 11:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.