Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use fuser command in Linux system

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to use the fuser command in the Linux system, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

Description:

Fuser can show which program is currently using a file, mount point, or even a network port on disk, and give details of the program process.

Fuser displays the process ID that uses the specified file or file system.

By default, each file name is followed by a letter to indicate the access type.

In zkfc's 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 there is no fuser command when minimizing the installation of centos

Yum install-y psmisc

Syntax:

Fuser (option) (parameter)

The access types are as follows:

C: represents the current directory

E: use this file as an executable object of the program

F: open file. It is not displayed by default.

F: an open file for write operations. It is not displayed by default.

R: indicates that the directory is the root of the process.

M: instructs the process to use this file for memory mapping, or whether the file is a shared library file and is mapped to memory by the process.

S: use this file as a shared library (or other loadable object)

Common option

-a: all files specified on the command line are displayed, and only the files accessed by default are displayed.

-c: same as-m, for POSIX compatibility.

-k: kill the process of accessing the file. If-signal is not specified, a SIGKILL signal is sent.

-I: ask the user before killing the process, if there is no-k this option will be ignored.

-l: lists all known signal names.

-m:name specifies a mounted file on the file system or a mounted block device (name name). In this way, all processes accessing the file or file system will be listed. If you specify a directory, it is automatically converted to "name/" and uses all file systems mounted under that directory.

-n:space specifies a different space. Different spatial files (file name, default here), tcp (local tcp port) and udp (local udp port) are supported here. For ports, you can specify the port number or name, and if it does not cause ambiguity, you can use a simple representation, such as name/space (that is, something like: 80/tcp).

-s: silent mode, at this time-uthmum 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 (for example,-HUP,-1). This option should be used with-k, otherwise it will be ignored.

-u: add the user name of the process owner after each PID.

-v: detailed mode. The output is like the output of the ps command, including many fields such as PID,USER,COMMAND. If it is accessed by the kernel, then PID is kernel. -V outputs the version number.

-4: use IPV4 sockets, which cannot be applied with-6 and are not ignored only when the tcp and udp names of-n exist.

-6: use IPV6 sockets, which cannot be applied with-4 and are not ignored only when the tcp and udp names of-n exist.

-reset all options and set the signal to SIGKILL.

Parameters.

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

Examples of use:

Displays process information that uses a file

This command is useful in umount to find out what else is used with the device.

?

one

two

three

$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 if you are sure before kill. It's best to add-v to know which process you're going to kill.

$fuser-m-k-I readme

Check out which programs use port 80 of tcp

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

Application of different fuser signals

The signals known to fuser can be listed with the-l parameter

?

one

two

three

four

[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 its known signal to the specified file process accessed instead of the SIGKILL sent by default with the-k parameter. For example, if you just suspend the process, you can send a HUP signal.

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

User process number permission command

?

one

two

three

four

/ 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 number of the local process that uses the / etc/passwd file, enter:

Fuser / etc/passwd

To list the process number and user login name of the process that uses the / etc/filesystems file, enter:

Fuser-u / etc/filesystems

The above is how to use the fuser command in the Linux system. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Original link: https://www.cnblogs.com/Sungeek/p/11857549.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report