Port view and shutdown process

1. View port occupancy

Execute in the windows command line window:

netstat -aon|findstr "8080" 
TCP     127.0.0.1:80         0.0.0.0:0               LISTENING       2448

The port "8080" is occupied by a process with a PID (process number) of 2448.

Check which application the port "8080" is occupied, and continue to execute the following command:

tasklist|findstr "2448"
notepad.exe                     2016 Console                 0     16,064 K

2. Shut down the process

2.1 Close the process according to the process number

taskkill /pid 2152

The multiple time format is:

taskkill /pid 2152 /pid 1284

2.2 Close the process by process name

To close notepad.exe, the format is:

taskkill /im notepad.exe

The format when specifying multiple is:

taskkill /im notepad.exe /im iexplorer.exe

If you want to close all, use the wildcard *, that is:

taskkill /im *.exe

2.3 Prompted shutdown process

taskkill /t /im notepad.exe
taskkill /t /pid 2152

This effect is to close after the prompt is confirmed by the user, and there is a prompt box.

2.4 Forcibly terminate the process

taskkill /f /im notepad.exe
taskkill /f /pid 2152

3. Port status

3.1 LISTENING state

After the FTP service is started, it is first in the listening (LISTENING) state.

3.2 ESTABLISHED state

ESTABLISHED means to establish a connection. Indicates that the two machines are communicating.

3.3 CLOSE_WAIT

The other party actively closes the connection or the network is abnormal and the connection is interrupted. At this time, our state will become CLOSE_WAIT. At this time, our side must call close() to make the connection close properly.

3.4 TIME_WAIT

Our party actively calls close() to disconnect, and the status changes to TIME_WAIT after receiving the other party's confirmation. The TCP protocol stipulates that the TIME_WAIT state will continue for 2MSL (that is, twice the maximum lifetime of the segment) to ensure that the old connection state will not affect the new connection. The resources occupied by the connection in the TIME_WAIT state will not be released by the kernel, so as a server, if possible, try not to actively disconnect the connection to reduce the waste of resources caused by the TIME_WAIT state.

At present, there is a way to avoid waste of TIME_WAIT resources is to turn off the LINGER option of the socket. However, this approach is not recommended for the TCP protocol. In some cases, this operation may cause errors.

3.5 SYN_SENT status

The SYN_SENT state means a connection is requested. When you want to access the services of other computers, you must first send a synchronization signal to the port. At this time, the state is SYN_SENT. If the connection is successful, it will become ESTABLISHED. At this time, the SYN_SENT state is very short. But if you find that there are a lot of SYN_SENTs and they are being sent to different machines, then your machine may be infected with a virus such as shock wave or sasser. In order for this type of virus to infect other computers, it must scan other computers. During the scanning process, a synchronization request must be issued to each computer to be scanned. This is also the reason for many SYN_SENTs.

Guess you like

Origin blog.csdn.net/qq_41358110/article/details/103215382