Current location - Quotes Website - Collection of slogans - How to check whether the port number is occupied?
How to check whether the port number is occupied?
In the debugging process of network programs, some unexpected things often happen, such as the failure to create TCP services. At this time, it is often necessary to check the network situation of the system. Of course, the most commonly used network packet capture mode is not WireShark mode. But often you only need to check the usage of a port, whether it is occupied by that process (corresponding to PID) or whether 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 to check the process name corresponding to this PID. If PID is not displayed, select PID in the menu view selection bar; When we know the process, we can kill it. Let me briefly talk about the processing methods I know under Windows and Linux systems. (If we need to determine who is occupying our 90 10 port)

1, Windows platform

Execute in a windows console window:

netstat -nao | findstr 90 10

TCP127.0.0.1:90100.0.0: 0 Monitoring 30 17.

What you see is that the process with PID of 30 17 occupies port 90 10. If you want to know more about its process name, you can use the following command:

Task list | findstr 30 17

If you want to terminate this process, you can of course terminate it in the task manager in the way described above, but if you want to improve efficiency, then use the taskkill command.

taskkill /pid 30 17

Then this process will be annihilated:) 2. Linux operating system

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

netstat -pan | grep 90 10

If you are a little more careful, you will find that you are using the netsta command. In fact, netstat is a general network statistics command, which is applicable to almost all popular operating systems, whether it is Linux, Window, other Unix or Unix-like operating systems, and its usage is basically the same.

The following is a detailed description of netstat command line parameters in Windows system.

Type:

Netstat [-a] [-e] [-n] [-o] [-p protocol] [-b] [-r] [-s] [-v] [interval] Parameter Description: -a shows all connections and listening ports.

-n Displays the address and port number as numbers.

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

-p In Windows systems, this option is used to specify a subset of the default cases. 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 Displays the executable components involved in creating each connection or listening port. In some cases, executable components are known to have multiple independent components, and in these cases; The sequence of components involved in creating a connection or listening port is displayed. In this case, the executable component name is at the bottom in [], the component it calls is at the top, and so on until the TCP/IP part. Please note this option.

It may take a long time, and it may fail if you don't have enough permissions.

-e Displays Ethernet statistics. This option can be used in combination 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 displays the routing table.

The -v option, when used with the -b option, displays the components included when creating a connection or listening port for all executable components.

Interval redisplays the selected statistics, pausing the time interval (in seconds) between each display. Press CTRL+C to stop redisplaying statistics. If omitted, netstat will display the current

Configuration information (displayed only once).