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.

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.