Learn How to Use ‘fuser’ Command with Examples in Linux

One of the most important task in Linux systems administration, is process management. Its involves several operations under monitoring, signaling processes as well as setting processes priorities on the system.

There are numerous Linux tools/utilities designed for monitoring/handling processes such as top, ps, pgrep, kill, killall, nice coupled with many others.

In this article, we shall uncover how to find processes using a resourceful Linux utility called fuser.

Suggested Read: Find Top Running Processes by Highest Memory and CPU Usage

fuser is a simple yet powerful command line utility intended to locate processes based on the files, directories or socket a particular process is accessing. In short, it helps a system user identify processes using files or sockets.

How to Use fuser in Linux Systems

The conventional syntax for using fuser is:

# fuser [options] [file|socket]
# fuser [options] -SIGNAL [file|socket]
# fuser -l 

Below are a few examples of using fuser to locate processes on your system.

Find Which Process Accessing a Directory

Running fuser command without any option will displays the PIDs of processes currently accessing your current working directory.

$ fuser .
OR
$ fuser /home/tecmint
Find Running Processes of Directory
Find Running Processes of Directory

For a more detailed and clear output, enable the -v or --verbose as follows. In the output, fuser prints out the name of the current directory, then columns of the process owner (USER), process ID (PID), the access type (ACCESS) and command (COMMAND) as in the image below.

$ fuser -v
List of Running Processes of Directory
List of Running Processes of Directory

Under the ACCESS column, you will see access types signified by the following letters:

  1. c – current directory
  2. e – an executable file being run
  3. f – open file, however, f is left out in the output
  4. F – open file for writing, F is as well excluded from the output
  5. r – root directory
  6. m – mmap’ed file or shared library

Find Which Process Accessing A File System

Next, you can determine which processes are accessing your ~.bashrc file like so:

$ fuser -v -m .bashrc

The option, -m NAME or --mount NAME means name all processes accessing the file NAME. In case you a spell out directory as NAME, it is spontaneously changed to NAME/, to use any file system that is possibly mounted on that directory.

Suggested Read: Find Top 15 Processes by Memory Usage in Linux

How to Kill and Signal Processes Using fuser

In this section we shall work through using fuser to kill and send signals to processes.

In order to kill a processes accessing a file or socket, employ the -k or --kill option like so:

$ sudo fuser -k .

To interactively kill a process, where you are that asked to confirm your intention to kill the processes accessing a file or socket, make use of -i or --interactive option:

$ sudo fuser -ki .
Interactively Kill Process in Linux
Interactively Kill Process in Linux

The two previous commands will kill all processes accessing your current directory, the default signal sent to the processes is SIGKILL, except when -SIGNAL is used.

Suggested Read: A Guide to Kill, Pkill and Killall Commands in Linux

You can list all the signals using the -l or --list-signals options as below:

$ sudo fuser --list-signals 
List All Kill Process Signals
List All Kill Process Signals

Therefore, you can send a signal to processes as in the next command, where SIGNAL is any of the signals listed in the output above.

$ sudo fuser -k -SIGNAL

For example, this command below sends the HUP signal to all processes that have your /boot directory open.

$ sudo fuser -k -HUP /boot 

Try to read through the fuser man page for advanced usage options, additional and more detailed information.

That is it for now, you can reach us by means of the feedback section below for any assistance that you possibly need or suggestions you wish to make.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

3 thoughts on “Learn How to Use ‘fuser’ Command with Examples in Linux”

  1. Great Article. I’ve seen it a lot of times but never knew what fuser was for. Thanks for the great article. I’d buy you a coffee, but I’m really poor. Keep up the good work.

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.