Linux system lsof command use instance summary

  

Linux system, lsof command can be used to find the name and number of files opened by the application, in addition, the losf command has many usages, the following system home small series will give Let's introduce the usage examples of the lsof command in Linux. Let's take a look.

lsof (list open files) list the current system is a tool to open the file. In the Linux environment, everything exists in the form of files. Not only can you access regular data through files, but you can also access network connections and hardware, such as Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) sockets. Etc., the system assigns a file descriptor to the application in the background. This file descriptor provides a common interface for the interaction between the application and the underlying operating system, regardless of the nature of the file. Because the list of descriptors for the application open file provides a lot of information about the application itself, it is helpful to be able to view this list through the lsof tool for system monitoring and troubleshooting.

1. Command format:

lsof [parameter][file]

2. Command function:

Used to view the files opened by your process, the process of opening files, the port opened by the process (TCP, UDP). Retrieve/recover deleted files. It is a very convenient system monitoring tool, because lsof needs to access core memory and various files, so it needs to be executed by the root user.

The file opened by lsof can be:

1. Ordinary file

2. Directory

3. File of network file system

4. Character or device file

5. (Function) shared library

6. Pipe, named pipe

7. Symbolic link

8. Network files (for example: NFS file, network socket, unix domain socket)

9. There are other types of files, etc.

3. Command parameters:

-a List the processes that exist for open files

-c "process name" List the files opened by the specified process

-g List GID numbers Process Details

-d "File Number" Lists the process that occupies the file number

+d "Directory" Lists the files opened in the directory

+D Directory Recursively lists the files that are opened in the directory

-n "Directory" Lists files using NFS

-i "Conditions" Lists the processes that meet the criteria. (4, 6, protocol, port, @ip)

-p "process number" List the file opened by the specified process number

-u List the UID number process details

-h Display help information

-v Display version information

4. Example:

Instance 1: No parameters

Command: lsof

Output:

The code is as follows:

[root@ Localhost ~]# lsof“/p” “p” COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

init 1 root cwd DIR 8,2 4096 2 /

init 1 root rtd DIR 8 ,2 4096 2 /

init 1 root txt REG 8,2 43496 6121706 /sbin/init

init 1 root mem REG 8,2 143600 7823908 /lib64/ld-2.5.so< Br>

init 1 root mem REG 8,2 1722304 7823915 /lib64/libc-2.5.so

init 1 root mem REG 8,2 23360 7823919 /lib64/libdl-2.5.so

init 1 root mem REG 8,2 95464 7824116 /lib64/libselinux.so.1

init 1 root mem REG 8,2 247496 7823947 /lib64/libsepol.so.1

init 1 root 10u FIFO 0,17 1233 /dev/initctl

migration 2 root cwd DIR 8,2 4096 2 /

migration 2 root rtd DIR 8,2 4096 2 /

migration 2 root txt unknown /proc/2/exe

k Softirqd 3 root cwd DIR 8,2 4096 2 /

ksoftirqd 3 root rtd DIR 8,2 4096 2 /

ksoftirqd 3 root txt unknown /proc/3/exe

migration 4 root cwd DIR 8,2 4096 2 /

migration 4 root rtd DIR 8,2 4096 2 /

migration 4 root txt unknown /proc/4/exe

ksoftirqd 5 root cwd DIR 8,2 4096 2 /

ksoftirqd 5 root rtd DIR 8,2 4096 2 /

ksoftirqd 5 root txt unknown /proc/5/exe

events/0 6 root cwd DIR 8,2 4096 2 /

events/0 6 root rtd DIR 8,2 4096 2 /

events/0 6 root txt unknown /proc /6/exe

events/1 7 root cwd DIR 8,2 4096 2 /

Description:

The meaning of the lsof output column information is as follows:

COMMAND: name of the process

PID: process identifier

PPID: parent process identifier (requires -R parameter)

USER: process owner

PGID: Process belongs to group

FD: file descriptor, By identifying the application descriptor file. Such as cwd, txt, etc.
Previous123Next page Total 3 pages

Copyright © Windows knowledge All Rights Reserved