Detailed explanation of fuser command usage in Linux

Detailed explanation of fuser command usage in Linux

describe:

fuser can show which program is currently using a file, mount point, or even network port on the disk, and provide detailed information about the program process.

fuser displays the process IDs that are using the specified file or file system.

By default each file name is followed by a letter indicating the access type.

In the zkfc log, there is a warn: PATH=$PATH:/sbin:/usr/sbin fuser -v -k -n tcp 8090 via ssh: bash: fuser: command not found

The reason is that when minimizing the installation of centos, there is no fuser command

yum install -y psmisc

grammar:

fuser(options)(parameters)

The access types are as follows:

c: represents the current directory
e: Use this file as the executable object of the program
f: The opened file. Not displayed by default.
F: File opened for writing. Not displayed by default.
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.
s: Use this file as a shared library (or other loadable object)

Common options

-a: Display all files specified in the command line. By default, only accessed files will be displayed.
-c: Same as -m, for POSIX compatibility.
-k: Kill the process accessing the file. If -signal is not specified, the SIGKILL signal is sent.
-i: Ask the user before killing the process. If there is no -k option, this option will be ignored.
-l: List all known signal names.
-m:name specifies a file on a mounted file system or a mounted block device (name name). In this way, all processes accessing this file or file system will be listed. If a directory is specified, it will be automatically converted to "name/" and all file systems mounted under that directory will be used.
-n:space specifies a different namespace (space). Different space files (file names, default here), tcp (local tcp port), and udp (local udp port) are supported here. For ports, you can specify the port number or name. If it does not cause ambiguity, you can use a simple representation, such as: name/space (that is, a representation such as: 80/tcp).
-s: Silent mode, -u and -v will be ignored. -a cannot be used with -s.
-signal: Use the specified signal instead of SIGKILL to kill the process. Signals can be represented by name or number (e.g. -HUP, -1). This option must be used with -k, otherwise it will be ignored.
-u: Add the user name of the process owner after each PID.
-v: Verbose mode. The output is similar to the output of the ps command, including PID, USER, COMMAND and many other fields. If it is accessed by the kernel, the PID is kernel. -V outputs the version number.
-4: Use IPV4 socket, cannot be used with -6, and will not be ignored only when the tcp and udp names of -n exist.
-6: Use IPV6 sockets. Cannot be used with -4. Will not be ignored only when the tcp and udp names of -n exist.
- Reset all options and set the signal to SIGKILL.

parameter

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

Example of use:

Display information about the processes using a file

This command is very useful when umounting, and can be used to find out what else is using this device.

$ fuser -um /dev/sda2 
/dev/sda2: 6378c(quietheart) 6534c(quietheart) 6628(quietheart) 
6653c(quietheart) 7429c(quietheart) 7549c(quietheart) 7608c(quietheart)

Kill the program that opens the readme file

Here, you will be asked to confirm before killing. It is best to add -v so that you know which process is going to be killed.

$ fuser -m -k -i readme

Check which programs use TCP port 80

$fuser -v -n tcp 80 or $fuser -v 80/tcp

Application of different fuser signals

Use the -l parameter to list the signals known to fuser.

[root@_mongodb_117 ~]# fuser -l
HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM
STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS
UNUSED

fuser can send a known signal to the process accessing the specified file instead of the SIGKILL sent by the -k parameter by default. For example, if you just want to suspend the process, then sending the HUP signal will suffice.

[root@_mongodb_117 ~]# fuser -v /root/install.log

User Process ID Permission Command

 /root/install.log: root 3347 f.... tail
[root@_mongodb_117 ~]# fuser -k -SIGHUP /root/install.log
 /root/install.log: 3347
[root@_mongodb_117 ~]# fuser -v /root/install.log

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

fuser /etc/passwd

To list the process numbers and user login names of processes that use the /etc/filesystems file, enter:

fuser -u /etc/filesystems

Summarize

This is the end of this article about the detailed usage of fuser command in Linux. For more related Linux fuser content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to use the Fuser command in Linux system

<<:  MySQL conditional query and or usage and priority example analysis

>>:  JavaScript to implement random roll call web page

Recommend

Minio lightweight object storage service installation and browser usage tutorial

Table of contents Introduction Install 1. Create ...

Why is UTF-8 not recommended in MySQL?

I recently encountered a bug where I was trying t...

Detailed tutorial on building nextcloud private cloud storage network disk

Nextcloud is an open source and free private clou...

Summary of react basics

Table of contents Preface start React Lifecycle R...

How to use shtml include

By applying it, some public areas of the website c...

Understand all aspects of HTTP Headers with pictures and text

What are HTTP Headers HTTP is an abbreviation of ...

Vue globally introduces scss (mixin)

Table of contents 1. mixin.scss 2. Single file us...

JavaScript realizes the drag effect of modal box

Here is a case of modal box dragging. The functio...

MySQL executes commands for external sql script files

Table of contents 1. Create a sql script file con...

Practical way to build selenium grid distributed environment with docker

Recently, I needed to test the zoom video confere...

Example of using CSS3 to customize the style of input multiple-select box

Principle: First hide the input element, then use...

Sample code for CSS dynamic loading bar effect

Using the knowledge of CSS variables, I will dire...