Lsof -- how to find out which process occupies the specified port in Linux

Source: Internet
Author: User
Article Title: lsof-how to find out which process occupies the specified port in Linux. Linux is a technology channel of the IT lab in China. Including desktop applications, Linux system management, kernel research, embedded systems, open source, and other basic classification lsof-I: 3306
Check who is using port 3306
Lsof Introduction
Lsof (list open files) is a tool used to list open files in the current system. In linux, everything exists in the form of a file. Through a file, you can not only access common data, but also access network connections and hardware. Therefore, for example, the transmission control protocol (tcp) and User Datagram Protocol (udp) sockets, the system assigns a file descriptor to the application at the backend, regardless of the nature of the file, this file descriptor provides a common interface for the interaction between the application and the basic operating system. Because the descriptor list of an Application Opening file provides a large amount of information about the application itself, it is very helpful for system monitoring and troubleshooting to view this list using the lsof tool.
Lsof usage
Meaning of lsof output information
Enter lsof in the terminal to display the files opened by the system. Because lsof needs to access the core memory and various files, it must be run as the root user to make full use of its functions.
Command pid user fd type device size node name
Init 1 root cwd dir 3, 3 1024 2/
Init 1 root rtd dir 3, 3 1024 2/
Init 1 root txt reg 38432 1763452/sbin/init
Init 1 root mem reg 106114 1091620/lib/libdl-2.6.so
Init 1 root mem reg 7560696 1091614/lib/libc-2.6.so
Init 1 root mem reg 79460 1091669/lib/libselinux. so.1
Init 1 root mem reg 223280 1091668/lib/libsepol. so.1
Init 1 root mem reg 564136 1091607/lib/ld-2.6.so
Init 1 root 10u fifo 1309/dev/initctl
Each line shows an opened file. If no conditions are specified, all files opened by all processes are displayed by default. The significance of lsof output column information is as follows:
Command: process name
Pid: process identifier
User: process owner
Fd: file descriptor. The application identifies the file through the file descriptor. Such as cwd and txt
Type: file type, such as dir and reg
Device: Specify the disk name.
Size: File size
Node: Index node (the identifier of the file on the disk)
Name: the exact name of the opened file.
The file descriptor cwd value in the fd column indicates the current working directory of the application, which is the directory started by the application unless it changes the directory.
Txt files are program code, such as application binary files or shared libraries. The second value indicates the application.
Program file descriptor, which is an integer returned when the file is opened. The last line of the above file/dev/initctl, whose file descriptor is 10. U indicates
Is the file opened and in read/write mode, not read-only? Or write-only (w) mode. At the same time, w indicates that the application has a write to the entire file.
Lock. This file descriptor is used to ensure that only one application instance can be opened at a time. Each application is initially opened with three file descriptors, from 0 to 2,
Standard input, output, and error streams. Therefore, the fd of files opened by most applications starts from 3.
The type column is more intuitive than the fd column. The files and directories are called reg and dir respectively. Chr and blk represent characters and Block devices respectively;
Or unix, fifo, or ipv4, indicating unix domain socket, first-in-first-out (fifo) queue, and Internet Protocol (ip) socket.

[1] [2] [3] Next page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.