fuser
Identify processes using files or sockets
TLDR
Find which processes are accessing a file or directory
Show more fields (USER, PID, ACCESS and COMMAND)
Identify processes using a TCP socket
Kill all processes accessing a file or directory (sends the SIGKILL signal)
Find which processes are accessing the filesystem containing a specific file or directory
Kill all processes with a TCP connection on a specific port
SYNOPSIS
fuser [-kansiuv] [-n space] [-SIGNAL] name...
PARAMETERS
-k
Kill processes accessing the file. Requires root privileges.
-i
Interactive mode. Ask user for confirmation before killing processes when used with -k.
-n space
Select a different namespace. space can be file, udp, or tcp.
-s
Silent mode. Only returns exit code if any processes are found.
-u
Display user ID along with process ID.
-v
Verbose mode. Displays more information about the processes and files involved.
-a
Show all files named on the command line, even if no process accesses them.
-m
Search for all files on the filesystem. name specifies a file on that filesystem.
-SIGNAL
Send SIGNAL to each process. Can be a signal name like HUP or a signal number.
name...
The file, directory, socket or file system to check for processes using it.
DESCRIPTION
The fuser command in Linux identifies processes using specified files or file systems. It displays the process IDs (PIDs) of processes that have opened a file, a directory, a socket, a named pipe, or a mount point.
fuser is invaluable for diagnosing resource contention or identifying processes that are preventing unmounting a file system. It can also be used to send signals to the identified processes, allowing for graceful termination or other management actions. For example, before unmounting a filesystem, fuser -m /mountpoint would show all processes accessing `/mountpoint`. This allows the system administrator to either wait for the processes to finish or signal them to terminate to allow unmounting. It is crucial for system administration and troubleshooting.
CAVEATS
Killing processes with fuser -k requires careful consideration, as it can lead to data loss or system instability. Ensure that you understand the implications before using this option. Insufficient permissions may limit fuser's ability to detect all processes.
EXAMPLES
- Find processes using a specific file: fuser /path/to/file
- Kill processes using a file system, interactively: fuser -ki /mnt/filesystem
- Find processes listening on port 8080 (TCP): fuser -n tcp 8080