Command Line to check which process occupies the port number

Source: Internet
Author: User

Some unexpected events often occur during network program debugging. For example, if a TCP service fails to be created, you must check the network conditions of the system, the most common network packet capture mode is not Wireshark. However, you often only need to check the usage of a port. It is occupied by the process (corresponding to the PID), or you need to kill it. If you are in a Windows operating system, you can run the netstat command to query the PID, and then open the task manager to view the process name corresponding to the PID. If the PID is not displayed, choose "View", "Select column", and select the PID. After learning about the process, we can kill the process. Next, I will briefly describe the processing methods in Windows and Linux. (If we need to determine who occupies our port 9010)

 

1. Windows Platform
Run the following command in the Windows console:
Netstat-nao | findstr" 9010"
TCP 127.0.0.1: 9010 0.0.0.0: 0 listening 3017

 

You can see that a process with a PID of 3017 occupies port 9010. If you want to know its process name, you can use the following command:

Tasklist | findstr" 3017"

 

If you want to kill the process, you can use the method described earlier to kill it in the task manager. But if you like efficiency, you can use the taskkill command.

Taskkill/PID 3017

Then this process will be wiped out :)

 

 

2. Linux

If you are a Linux enthusiast, you should be familiar with this command,

Netstat-Pan | grep 9010

 

 

If you are a little more careful, you will find that all the netsta commands are used. In fact, netstat is a common network statistics command, which is applicable to almost all popular operating systems, whether it is a Linux, window, or other UNIX or Unix-like operating system, the usage is basically the same.

 

The following is a detailed explanation of the netstat command line parameters in windows.

 

Format:

Netstat [-A] [-E] [-N] [-O] [-P Protocol] [-B] [-R] [-S] [-V] [Interval]

 

Parameter description:

-A displays all connection and listening ports.
-N: the address and port number are displayed in numbers.

-O displays the ID of the process associated with each connection.

 

-P in windows, this option is used to specify the default subset. PROTO displays the connection of the Protocol specified by Proto. proto can be one of the following protocols: TCP, UDP, tcpv6 or udpv6.

If used with the-s option to display statistics by Protocol, proto can be one of the following protocols:
IP, IPv6, ICMP, ICMPv6, TCP, tcpv6, UDP, or udpv6.

-B shows the executable components that contain each connection or listening port. In some cases, it is known that an executable component has multiple independent components, and in these cases, a sequence of components contained in the creation of a connection or listening port is displayed. In this case, the executable component name is in the [] at the bottom, and the component called by the component is at the top until the TCP/IP part. Note this option
It may take a long time. If you do not have sufficient permissions, it may fail.

-E displays Ethernet statistics. This option can be combined with the-s option.

-S displays statistics by protocol. By default, statistics of IP, IPv6, ICMP, ICMPv6, TCP, tcpv6, UDP, and udpv6 are displayed.

 

-R shows the route table.

When used together with option-B, components that contain connection or listening ports are displayed for All executable components.

Interval re-displays the selected statistics. The pause interval between each display (in seconds ). Press Ctrl + C to stop displaying statistics again. If omitted, netstat displays the current
Configuration Information (only once ).

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.