Using fuser to find running process in system

Posted on 7:50 PM by Bharathvn

Another way to locate a particular process is by what the process is accessing. The
fuser command can be used to find which processes have a file or a socket open
at the moment. After the processes are found, fuser can be used to send signals to
those processes.

The fuser command is most useful for finding out if files are being held open
by processes on mounted file systems (such as local hard disks or Samba shares).
Finding those processes allows you to close them properly (or just kill them if you
must) so the file system can be unmounted cleanly.

Here are some examples of the fuser command for listing processes that have files open on a selected file system:

$ fuser -mauv /boot Verbose output of processes with /boot open
USER PID ACCESS COMMAND
/boot/grub/: root 3853 ..c.. (root)bash
root 19760 ..c.. (root)bash
root 28171 F.c.. (root)vi
root 29252 ..c.. (root)man
root 29255 ..c.. (root)sh
root 29396 F.c.. (root)vi

The example just shown displays the process ID for running processes associated with
/boot. They may have a file open, a shell open, or be a child process of a shell with the current directory in /boot. Specifically in this example, there are two bash shells open in the /boot file system, two vi commands with files open in /boot, and a man command running in /boot. The -a shows all processes, -u indicates which user owns each process, and -v produces verbose output.