fuseris one of the *nix commands that I have started seeing myself use more and more frequently. It is a very powerful command, yet often forgotten. So what is it?
fuserdisplays the process IDs of the processes that are using the files specified. Identifying Processes
The following example shows how you can use the
fusercommand to find out which process is writing a log file called
fusertells you the process ID (24976), which you can then use in a
pscommand to find out what the process is. In this case, its java.
sharfah@starship:~> ls -ltr -rw-rw-r-- 1 sharfah sharfah 2836 Aug 6 00:08 log.txt sharfah@starship:~> fuser -u log.txt log.txt: 24976o(sharfah) sharfah@starship:~> ps -ef | grep 24976 sharfah 24976 24963 0 23:49:00 ? 13:39 java -server sharfah 6284 17191 0 00:09:54 pts/1 0:00 grep 24976Used in this way,
fusercan help tell you which process is responsible for creating large log files on your filesystem! Killing Processes
-kflag, sends the SIGKILL signal to each process using the file. This is handy if you want to "kill -9" a process without hunting for its PID first. Alternatively, if you want to send another signal type, use the
-sflag. e.g. to send SIGTERM use
-s TERM. The
-koption is equivalent to
-s 9. Most of my shutdown scripts, simply call
fuser -s TERMon the process's log file. Because
fuserworks with a snapshot of the system image, it may miss processes that begin using a file while fuser is running. Also, processes reported as using a file may have stopped using it while
fuserwas running. These factors should discourage the use of the