- 首先是 win+R,然后輸入cmd,打開命令行
- 然后輸入 netstat –ano,可以看到
C:\Users\sfxu>netstat -ano
活動連接
協(xié)議 本地地址 外部地址 狀態(tài) PID
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 640
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 3912
TCP 0.0.0.0:4369 0.0.0.0:0 LISTENING 8792
每行的最后一位為PID,就是進程號。
- 利用管道命令,輸入netstat -ano | findstr "指定端口"
C:\Users\sfxu>netstat -ano | findstr "8888"
TCP 0.0.0.0:8888 0.0.0.0:0 LISTENING 4576
TCP [::]:8888 [::]:0 LISTENING 4576
可以看到時進程號為4576的進程占用了8888端口
- 輸入tasklist,可以看到
映像名稱 PID 會話名 會話# 內(nèi)存使用
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 8 K
System 4 Services 0 16 K
smss.exe 412 Services 0 76 K
csrss.exe 736 Services 0 1,860 K
wininit.exe 836 Services 0 492 K
每行最左邊為這個進程的名字
- 利用管道命令,輸入tasklist | findstr 4576
C:\Users\sfxu>tasklist | findstr 4576
java.exe 4576 Console 6 56,296 K
可以看到j(luò)ava.exe的進程號為4576,也就是java.exe占用了8888端口
- 輸入taskkill /f /t /im 進程名稱,來殺死進程
C:\Users\sfxu>taskkill /f /t /im java.exe
成功: 已終止 PID 10152 (屬于 PID 4576 子進程)的進程。
成功: 已終止 PID 4576 (屬于 PID 22928 子進程)的進程。