In the Windows operating system, the query port consumes and clears the ports that are used by the program

Source: Internet
Author: User

One, in the Windows operating system, the query port occupies and clears the port occupied by the program

After elevation of privilege by: Netstat-b
or with

1. The process ID that the query port occupies

Click "Start" and "Run", enter "CMD" and click on the OK button to enter the DOS window, then run the following command separately:
NETSTAT-A-N each port occupied
Netstat-ano each port occupancy and process PID
Netstat-aon | Findstr "80"
C:\users\admin>netstat-aon|findstr "80"
TCP 127.0.0.1:9080 0.0.0.0:0 LISTENING 4632

2. View the application for the port number
tasklist | Findstr "4632"

Added: Tasklist/fi "pid eq 4632"
GROOVE. EXE 4632 Console 1 84,880 K
It is clear that the GROOVE.EXE occupies 80 ports, GROOVE. EXE an IE ActiveX control.

3. Terminate the process
Taskkill/pid 4632/f
or use taskkill/f/t/im GROOVE.exe

Query again for successful termination
tasklist | Findstr "4632"
If the execution of this command is terminated successfully, it should return null., which indicates success, terminates the PID 4632 process.

Second, in the Linux operating system, the query port occupies and clears the port occupation of the program

1, the query port number occupies, according to the port to view process information

[Email protected] ~]# lsof-i:80
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
httpd 5014 root 3u IPv4 14346 TCP server2:http (LISTEN)
2. View the executable program corresponding to the process according to the process number
PS-F-P Process number
# ps-f-P 5014
UID PID PPID C stime TTY time CMD
Root 5014 1 0 17:26? 00:00:00/usr/local/apache/bin/httpd-k
3. View dynamic links according to executable program
LDD executable file name

Ldd/usr/local/apache/bin/httpd
Linux-vdso.so.1 = (0x00007fff9dc90000)
libaprutil-0.so.0 =/usr/local/apache/lib/libaprutil-0.so.0 (0x00002af026fcd000)
4, according to the port number to get the process of the details of its occupation

Netstat-tlnp|grep 80
TCP 0 0 192.168.33.10:80 0.0.0.0:* LISTEN 5014/httpd
TCP 0 0 0.0.0.0:48054 0.0.0.0:* LISTEN 5386/java

This step equals the 122 steps just above

5, according to the port number query, query its occupation process ID

Netstat-tlnp|grep 80|awk ' {print $7} ' |awk-f '/' {print '} '
5014
or with the following command

Netstat-pan|grep 80

NETSTAT [-A] [-b] [-e] [-n] [-O] [-P proto] [-r] [-S] [-v] [interval]
-a displays all connections and listening ports.
-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 independent components, and in these cases a sequence of components that are included in creating a connection or listening port is displayed. In this case, the executable component name is in the bottom [], the top is the component it calls, and so on, until the TCP/IP section. Note This option may take a long time and may fail if insufficient permissions are available.

-e Displays Ethernet statistics. This option can be used in combination with the-s option.
-N Displays the address and port number in digital form.
-O Displays the owning process ID associated with each connection.
-p proto shows the connection to 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 per-protocol statistics, Proto can be one of the following protocols: IP, IPV6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPV6.
-r Displays the routing table.
-S displays statistical information by protocol. By default, the statistics for IP, IPV6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6 are displayed;
The-p option specifies a subset of the default conditions.
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 re-displays the selected statistics, pausing the interval (in seconds) between each display. Press CTRL + C to stop displaying the statistics again. If omitted, netstat displays the current configuration information (only once)

6, one-time removal of 80 port-occupied programs

Lsof-i: 80|grep-v "PID" |awk ' {print ' kill-9 ', $ $} ' |sh

7, manual termination of the operation of the process

Kill 5014
Can be forced to terminate if not terminated
Kill-9 5014
Lsof-i:80

Should not be able to query the occupied process.

In the Windows operating system, the query port consumes and clears the ports that are used by the program

Related Article

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.