Command of the Day: fuser

May 2, 2007

This one is pretty cool – fuser identifies the process id of any processes that are using a specific file or filesystem. This is something I need frequently on Windows when debugging service or multi-user tests. Invariably there will be a race condition that is causing cleanup to not succeed because the cleanup thread has gotten ahead of the app or test thread(s). When that happens the cleanup thread is unable to move or delete log files, temp data, etc.

I’m left wondering who had the file open. There are many ways to find this but I normally use a SysInternals tool to check which process has the open handle. Problem is this isn’t easy to automate so by the time I’m looking for the file lock it’s already gone.

Using fuser I can add this functionality right into my test suites.

To test fuser I performed a more operation on a file in my home directory and left the more process blocked with the file open. That command was:

username@desktop:~$ more menu.lst

In another terminal window I then executed:

username@desktop:~$ fuser -u menu.lst
menu.lst:             5829(username)

So process 5829 being run by the user “username” has the file menu.lst open.

Now I can use ps to figure out what command that user is running (and on what tty).

username@desktop:~$ ps 5829
5829 pts/1    S+     0:00 more menu.lst

I think I need to try piping all of that together into one operation.

5 Responses to “Command of the Day: fuser”

  1. I’m curious now – are you really a Microsoft employee? Can you mail me from your work address (you should be able to look up mine)?

  2. Camouflage Says:

    You can check what command user is running to access the file with -v option:
    fuser -v /boot/grub/menu.lst

    /boot/grub/menu.lst: username 9337 f…. more

    You could combine fuser and ps like this:
    ps `fuser menu.lst 2>/dev/null`

  3. Unlocker Says:

    Fuser is a great command. There are several Windows utilities that do similar things. The one i use is Unlocker (

  4. Alex Says:

    You should learn about … lsof
    Its probably the most useful utility on any *nix box.

    Quick tip: since you can access almost any resource in Linux using simple file handles, imagine the possibilities of lsof😉

  5. Onno Zweers Says:

    People who are interested in fuser may also be interested in lsof (list open files).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: