fuser

process managementLinux/Unix
The fuser command is one of the most frequently used commands in Linux/Unix-like operating systems. fuser The fuser command identifies processes using files or sockets. It helps you find which processes are accessing specific files, directories, or sockets, making it useful for troubleshooting and system administration. You can also use it to send signals to these processes, allowing you to terminate applications that are preventing operations like unmounting filesystems.

Quick Reference

Command Name:

fuser

Category:

process management

Platform:

Linux/Unix

Basic Usage:

fuser [options] [arguments]

Common Use Cases

    Syntax

    fuser [options] file|directory... 
    fuser [options] [-n namespace] name...

    Options

    Option Description
    -a, --all Show all files specified, not just those being accessed by processes
    -k, --kill Kill processes accessing the file (SIGKILL is default signal)
    -i, --interactive Ask for confirmation before killing
    -l, --list-signals List available signal names
    -m, --mount Show all processes using the mounted filesystem containing the specified file
    -n, --namespace NAMESPACE Use this namespace (file, udp, tcp, etc.)
    -s, --silent Silent operation, no output shown
    -SIGNAL Send specified signal instead of SIGKILL when used with -k
    -u, --user Append the user name of the process owner
    -v, --verbose Verbose output, shows more details about processes
    -w, --wait Wait for all killed processes to die (with -k)
    -4, --ipv4 Search only for IPv4 sockets
    -6, --ipv6 Search only for IPv6 sockets

    Examples

    How to Use These Examples

    The examples below show common ways to use the fuser command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    #

    Basic Usage:

    fuser /var/log/syslog

    Show processes using the syslog file.

    fuser -v /home/user/document.txt

    Verbose output showing detailed information about processes using the specified file.

    Finding Processes Using Mounted Filesystems:

    fuser -m /mnt/usb

    Show all processes using files in the /mnt/usb mount point.

    fuser -vm /home

    Verbose listing of all processes using the /home filesystem.

    Network Socket Operations:

    fuser -n tcp 80

    Show processes using TCP port 80.

    fuser -vn udp 53

    Verbose output of processes using UDP port 53.

    Signal Operations:

    fuser -k /var/run/program.pid

    Kill all processes accessing the specified PID file (sends SIGKILL).

    fuser -k -TERM /mnt/external

    Terminate (SIGTERM) all processes using the /mnt/external mount point.

    fuser -k -HUP -m /var/www/html

    Send SIGHUP to all processes using files in the /var/www/html directory.

    Interactive Mode:

    fuser -i -k /media/usb

    Interactively kill processes using /media/usb (asks for confirmation before killing each process).

    Combined Operations:

    fuser -vm -k -TERM /mnt/usb

    Verbose listing and terminate (with SIGTERM) all processes using the /mnt/usb filesystem.

    fuser -vm -k -15 -w /mnt/disk

    List, send SIGTERM, and wait until all processes using /mnt/disk have terminated.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    Access Types:

    When using verbose mode (-v), fuser shows how each process is accessing the file using these access type indicators:

    • c: Current directory - The process's current directory is on the specified filesystem
    • e: Executable - The process is executing a file on the specified filesystem
    • f: Open file - The process has a file open on the specified filesystem
    • F: Open file for writing - The process has a file open for writing
    • r: Root directory - The process's root directory is on the specified filesystem
    • m: mmap'ed file or shared library - The process has a memory-mapped file or library

    Namespaces:

    • file: Files and directories (default namespace)
    • tcp: TCP sockets
    • udp: UDP sockets
    • unix: Unix domain sockets

    Unmounting Filesystems:

    • One of the most common uses of fuser is to find processes preventing a filesystem from being unmounted
    • Use fuser -vm /mount/point to see all processes using a filesystem
    • Then use fuser -km /mount/point to kill those processes if necessary
    • For safer termination, use fuser -km -15 -w /mount/point to send SIGTERM and wait for processes to exit

    Network Applications:

    • Use fuser -n tcp 80 to identify which process is using port 80
    • Helpful for troubleshooting "address already in use" errors
    • Check if servers are running on expected ports
    • Identify rogue applications using network ports

    Security Considerations:

    • Using fuser -k to kill processes can be dangerous on critical system files
    • Always use -i (interactive) flag when killing processes on important systems
    • Root privileges are required to see all processes and to kill processes owned by other users
    • Be extremely careful with the -m option on system directories like / or /usr

    Performance Impact:

    • On large filesystems with many files, fuser can be resource-intensive
    • For better performance on large systems, consider more targeted approaches
    • Using lsof may provide more detailed information but at a higher performance cost

    Signal Handling:

    • SIGKILL (signal 9) is the default when using -k option
    • SIGTERM (signal 15) is often a better first choice as it allows programs to exit cleanly
    • SIGHUP (signal 1) can be used to make many services reload their configuration
    • Use fuser -l to see all available signals

    Limitations:

    • Cannot detect processes using remote NFS files on some systems
    • May not detect all types of file access in certain edge cases
    • Not all processes respond to signals in the expected way
    • Some system processes cannot be killed, even with SIGKILL

    Compatibility Notes:

    • The behavior and available options may vary between different Unix/Linux distributions
    • On some systems, fuser is part of the psmisc package
    • BSD variants might have different syntax or capabilities
    • Always check the man page on your specific system

    Related Commands:

    • lsof - List open files (more detailed than fuser but often slower)
    • ps - Report process status
    • kill - Send signals to processes
    • pkill - Signal processes based on name and other attributes
    • netstat - Network statistics (alternative for port usage)
    • ss - Another utility to investigate sockets
    • umount - Unmount filesystems

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the fuser command works in different scenarios.

    $ fuser
    View All Commands