×


Fuser Command in Linux - Explained with examples



Files and folders in Linux are accessed by processes of a particular identity. You must know the id of the specific process if you want to perform any action on that process.

It is among the most important tasks of Linux systems administrators. It is involved in a number of activities under supervision, signaling processes, and setting the priorities of processes on the system.

Here at LinuxAPT, we shall look into how to find processes by using the fuser command in Linux.


What is the syntax of the fuser command ?

It's syntax is given below:

$ fuser [options] [file|socket]
$ fuser [options] -SIGNAL [file|socket]
$ fuser -l

Or you can look up usage with the command:

$ fuser


How to use the fuser command ?

1. Check the process detail accessing

$ fuser -v .

This will display USER, PID, ACCESS and COMMAND.

For example, To check the processes accessing of file test, run the below command:

$ fuser -v -m test


2. Kill  signal

For example, to kill all the processes, run the command:

$ fuser -k .

To use -ki option to ask yes/no:

$ fuser -ki .


3. List all signals:

$ fuser -l


[Need help in fixing Linux system issues ? We can help you. ]


Conclusion

This article covers how to find processes by using the fuser command in Linux. In fact, the fuser command is primarily used to identify processes using files, directories, or sockets.

fuser command Options includes:

  • -a, --all: Show all files specified on the command line. By default, only files that are accessed by at least one process are shown.
  • -c: Same as -m option, used for POSIX compatibility.
  • -f: Silently ignored, used for POSIX compatibility.
  • -k, --kill: Kill processes accessing the file. Unless changed with -SIGNAL, SIGKILL is sent. An fuser process never kills itself, but may kill other fuser processes. The effective user ID of the process executing fuser is set to its real user ID before attempting to kill.
  • -i, --interactive: Ask the user for confirmation before killing a process. This option is silently ignored if -k is not also present.
  • -l, --list-signals: List all known signal names.
  • -m NAME,
  • --mount NAME NAME: specifies a file on a mounted file system or a block device that is mounted. All processes accessing files on that file system are listed. If a directory file is specified, it is automatically changed to NAME/. to use any file system that might be mounted on that directory.
  • -M, --ismountpoint: Request is fulfilled only if NAME specifies a mountpoint. This is an invaluable seatbelt which prevents you from killing the machine if NAME happens to not be a filesystem.
  • -w: Kill only processes which have write access. This option is silently ignored if -k is not also present.
  • -n: SPACE,
  • --namespace SPACE: Select a different name space. The name spaces file (file names, the default), udp (local UDP ports), and tcp (local TCP ports) are supported. For ports, either the port number or the symbolic name can be specified. If there is no ambiguity, the shortcut notation name/space (e.g., 80/tcp) can be used.
  • -s, --silent: Silent operation. -u and -v are ignored in this mode. -a must not be used with -s.
  • -SIGNAL: Use the specified signal instead of SIGKILL when killing processes. Signals can be specified either by name (e.g., -HUP) or by number (e.g., -1). This option is silently ignored if the -k option is not also present.
  • -u, --user: Append the username of the process owner to each PID.
  • -v, --verbose: Verbose mode. Processes are shown in a ps-like style. The fields PID, USER, and COMMAND are similar to ps. ACCESS shows how the process accesses the file. Verbose mode also shows when a particular file is being access as a mount point, knfs export or swap file. In this case, kernel is shown instead of the PID.
  • -V, --version: Display version information.
  • -4, --ipv4: Search only for IPv4 sockets. This option must not be used with the -6 option and only has an effect with the tcp and udp namespaces.
  • -6, --ipv6: Search only for IPv6 sockets. This option must not be used with the -4 option and only has an effect with the tcp and udp namespaces.
  • - : Reset all options and set the signal back to SIGKILL.

More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com