Find out which process is consuming commands for a port number

Source: Internet
Author: User

Find out which process is consuming commands for a port number

1) Use the lsof command
Lsof is a very powerful Linux tool that she is used to find out which programs use those files. Under the Linux system, basically everything can be used as a file. The socket is, of course, a file. So lsof can be used to find out who used a certain port. Specific methods:
lsof-i:p ort_number |grep "(LISTEN)"
-I is used to find and network related files, ":" is required, it is the flag you are looking for is a port. Port_number is the port number you're looking for, for example, if you're looking for a program that uses Oracle's listening port 1521, you can use Lsof-i: 1521 |grep "(LISTEN)". If a program is already occupied, then the second field printed below is the process ID of the program, and the first field is the name of the process.
if only losf-i:p Ort_number may be able to find many applications, but these programs do not actually occupy the ports you specify, these ports are simply connected to this machine or another machine. So grep "(LISTEN)", because a port can only be occupied by a program, so this method is reliable.

2) Use the netstat command
we must be familiar with this command, perhaps you have never thought of using the arrival to find which program occupies the specified port. But Netstat-an does provide this functionality. So there is a problem must think first to find the man manual, but to tell the truth, some man manual written so that the Chinese can not understand, there is no way, Googe or Baidu.
To execute the man netstat command, you will find that Netstat provides the '-P ' option, which is the function of telling you which program is occupying the port, but the form she offers is more bizarre and pid/process_name provided. PID is, of course, the process ID, and process_name is the command of the process, separated by the '/' number in the middle.
As with the above reasons, we only look for listen ports, Netstat gives us the option of-L, which is not the default option.
Here's a 1521-port look at how to find the program, we use the following command:
Netstat-lnp|awk ' begin{prt= ': 1521$ "}{if ($4 ~ prt) print $} '
in this case, awk is used to match the pattern of the 4th field in order to avoid a miscarriage of judgment.

Find out which process is consuming commands for a port number

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.