spockrules - 2012-11-12

[What is this utility?]

It is a very simple utility that employs only a couple of features of the Unix/Linux fuser utility.

This utility can be used to see all the open files and what processes have them open. It can also be used to see if any processes are accessing a file, and if so, tell you who they are.

The SysInternals utility named 'handle.exe' (downloadable from Microsoft) suits most people's needs. If you're dealing with a file or directory that is in use, you can run it and then scan the output for what you're looking for.

However, if you're dealing with "in use" files in scripts, then handle.exe is not a very useful tool without some elaborate scripting. It always exits 0, so you can't check the return code to see if a particular file is in use or not -- you have to actually scan the output. Also, it does pattern matching. Even if you specify a full path, it still does pattern matching. In that case, it is very unlikely it will get a false positive, but you never know.

The fuser utility can be run in two modes:

  • Just run fuser.exe: it will show all open files and the processes that have them open.

  • fuser filename. The program will figure out the full path of the filename you specify, if you don't specify a full path. Then it will do an EXACT MATCH against the list of open files to determine if it is in use or not. It will return 1 if noone is accessing it, or 0 if there is at least one process accessing it.

The greatest benefits:

  • You can run fuser with a relative pathname and it will tell you if it is in use or not. You don't have to worry about grepping the output and worrying about false positives -- it just works.

  • You can easily use this in scripts.

 

Last edit: spockrules 2012-11-12