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

MySql sets the specified user database view query permissions

1. Create a new user: 1. Execute SQL statement to...

Detailed explanation of how to use Vue self-nested tree components

This article shares with you how to use the Vue s...

CSS to achieve the sticky effect of two balls intersecting sample code

This is an effect created purely using CSS. To pu...

Various types of MySQL indexes

What is an index? An index is a data structure th...

Share 16 burning flame effect English fonts treasure trove

We live in a visual world and are surrounded by m...

Draw a heart with CSS3

Achieve resultsRequirements/Functionality: How to...

Native JavaScript carousel implementation method

This article shares the implementation method of ...

Basic learning and experience sharing of MySQL transactions

A transaction is a logical group of operations. E...

A small problem about null values ​​in MySQL

Today, when testing the null value, I found a sma...

A brief discussion on the role of HTML empty links

Empty link: That is, there is no link with a targ...

MySQL uses frm files and ibd files to restore table data

Table of contents Introduction to frm files and i...

Web Design Tutorial (1): Steps and Overall Layout

<br /> Note: All texts, except those indicat...

A brief introduction to VUE uni-app core knowledge

Table of contents specification a. The page file ...

Centos builds chrony time synchronization server process diagram

My environment: 3 centos7.5 1804 master 192.168.1...