TrumanWong

fuser

Identify a process using a file or file structure

Supplementary instructions

fuser command is used to report files and network sockets used by a process. The fuser command lists the process numbers of local processes that use the file, local or remote file specified by the parameter. For blocking special devices, this command lists the processes using any files on the device.

Each process number is followed by a letter that indicates how the process uses the file.

  • c: Indicates the working directory of the process.
  • e: Indicates that the file is an executable file of the process (that is, the process is started by this file).
  • f: Indicates that the file is opened by the process. By default, the f character is not displayed.
  • F: Indicates that the file is opened by the process for writing. By default, the F character is not displayed.
  • r: Indicates that the directory is the root directory of the process.
  • m: Instructs the process to use the file for memory mapping, or the file is a shared library file and is mapped into memory by the process.

grammar

fuser(option)(parameter)

Options

-a: Display all files specified on the command line;
-k: Kill all processes accessing the specified file;
-i: User confirmation is required before killing the process;
-l: List all known signal names;
-m: Specify a loaded file system or a loaded block device;
-n: Select a different namespace;
-u: Display the user name after each process.

Parameters

File: It can be a file name or a TCP or UDP port number.

Example

To list the process numbers of local processes using the /etc/passwd file, enter:

fuser /etc/passwd

To list the process IDs and user logins of processes using the /etc/filesystems file, enter:

fuser -u /etc/filesystems

To terminate all processes using a given file system, enter:

fuser -k -x -u -c /dev/hd1 or fuser -kxuc /home

Either command lists the process ID and user name, and then terminates each process that is using the /dev/hd1 (/home) file system. Only the root user can terminate a process belonging to another user. You may want to use this command if you are trying to dismount the /dev/hd1 file system and a process that is accessing the /dev/hd1 file system does not allow this.

To list all processes that are using files that have been removed from a given file system, enter:

fuser -d /usr file

/dev/kmem is used for system images. /dev/mem is also used for system images.