Home > Process Management > fuser

fuser: Find processes using files or sockets

The fuser command is used to identify the PIDs of processes that are using a specific file, filesystem mount point, or network socket. This is useful for system administrators to find and terminate processes that are locking resources or to troubleshoot issues.

Overview

fuser outputs the PIDs of processes that are using a specified file, directory, or network port. This allows you to easily identify which processes are occupying specific resources and, if necessary, terminate those processes.

Key Features

  • Identify processes using files/directories
  • Identify processes using network ports (TCP/UDP)
  • Provides functionality to forcefully terminate identified processes
  • Check for processes using a mount point before unmounting

Key Options

The main options of the fuser command help to configure various aspects of process identification and control.

Basic Operations

Output Formats

Generated command:

Try combining the commands.

Description:

`fuser` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Effectively manage processes using file and network resources with various usage examples of the fuser command.

Find processes using a specific file

fuser /var/log/syslog

Find the PIDs of processes using the `/var/log/syslog` file.

Find processes using a mount point

fuser -m /mnt/usb_drive

Find all processes using the `/mnt/usb_drive` mount point.

Find processes using a specific TCP port

fuser -n tcp 80

Find the PIDs of processes using TCP port 80 (HTTP).

View detailed information with user names

fuser -uv /home/user/document.txt

Display detailed PIDs and usernames of processes using the `/home/user/document.txt` file.

Forcefully terminate processes using a file

sudo fuser -k /tmp/locked_file.txt

Forcefully terminate all processes using the `/tmp/locked_file.txt` file. (Caution: Using this on critical processes may lead to system instability)

Terminate processes using a specific UDP port

sudo fuser -k -n udp 53

Forcefully terminate processes using UDP port 53 (DNS).

Installation

fuser is typically installed by default as part of the `psmisc` package on most Linux distributions. If fuser is not present on your system, you can install it using the following commands.

Debian/Ubuntu

sudo apt update && sudo apt install psmisc

Install using the apt package manager.

CentOS/RHEL/Fedora

sudo yum install psmisc
# or
sudo dnf install psmisc

Install using the yum or dnf package manager.

Tips & Precautions

Useful tips and precautions when using the fuser command.

Caution when using fuser -k

The `-k` option forcefully terminates processes. Using it on critical system processes can lead to system instability or data loss. Carefully check which processes will be terminated before using it.

  • Recommendation: First, run `fuser` without the `-k` option to see which processes are affected, and then use the `-k` option only if necessary.

Comparison with lsof

Both fuser and lsof are used to find processes using open files and sockets, but they differ in their purpose and output format.

  • fuser: Primarily specialized for quickly finding the PIDs of processes using specific files/sockets.
  • lsof: Provides much more detailed information about open files and has a wide range of filtering and output options.

Permission Issues

You may need `sudo` privileges to check or terminate system files, other users' processes, or specific network ports.

  • Permissions: In most cases, it is recommended to run `fuser` using `sudo`.

Same category commands