How to see which process the port number is occupied by

Source: Internet
Author: User

How to see which process the port number is occupied by

In the process of debugging a network program, often some unexpected things happen, such as the creation of a TCP service failure, this time often need to look at the network situation of the system, the most commonly used network grab package of course Wireshark mode. But often you just need to look at the usage of a certain port, which is occupied by that process (the corresponding PID), or you need to kill it. If you are in the Windows operating system, you can use the Netstat command to query the PID, and then you can open the Task Manager, see the PID corresponding process name, if the PID does not show, menu "Check" Select the column to select the PID can be, know that after the process, we can kill the process. Let me briefly describe what I know about how to handle Windows and Linux systems. (If we need to determine who is taking up our 9010 ports)

1. Windows platform
Execute under Windows console window:
Netstat-nao | Findstr "9010"
TCP 127.0.0.1:9010 0.0.0.0:0 Listening 3017

You see that the PID 3017 process takes up 9010 ports, and if further 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, of course, kill it in the task manager in the way described earlier, but if you prefer to be more efficient, use the Taskkill command.

Taskkill/pid 3017

Then the process is dimmed:

2, Linux

If you're 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 the Netsta command is used, in fact, Netstat is a more common network statistics command, almost all of the current popular operating system, whether it is Linux,window, or other Unix, or unix-like operating system, and the usage is basically consistent.

The following is a detailed explanation of the netstat command-line parameters in a Windows system.

Format:

netstat [-a] [E] [-n] [-O] [-P Protocol] [-b] [-r] [-S] [-v] [Interval]

Parameter description:

-a displays all connections and listening ports.
-N Displays the address and port number in digital form.

-O Displays the owning process ID associated with each connection.

-P in Windows systems, this option specifies a subset of the default conditions. Proto Displays the connection proto the specified protocol; Proto can be one of the following protocols: TCP, UDP, TCPv6, or UDPV6.

If used with the-s option to display by protocol statistics, Proto can be one of the following protocols:
IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPV6.


-B Displays the executable components that are included in creating each connection or listening port. In some cases the executable component is known to have multiple stand-alone components, and in these cases the sequence of components contained in the Create connection or listening port is displayed. In this case, the executable component name is at the bottom of [], the top is the component it calls, and so on, until the TCP/IP section. Note this option
It may take a long time, and if you do not have sufficient permissions, you may fail.

-e Displays Ethernet statistics. This option can be used in combination with the-s option.


-S displays by protocol statistics. By default, statistics for IP, IPV6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6 are displayed.

-r Displays the routing table.

The-V is used with the-B option to display components that are included in creating a connection or listening port for all executable components.

Interval the selected statistics again, pausing interval (in seconds) between each display. Press CTRL + C to stop the statistics from being displayed again. If omitted, Netstat displays the current
Configuration information (shown 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.