windows 查看进程占用的端口号
tasklist
查看当前运行的进程
netstat
netstat -ano | findStr PID
查看某个进程占用了哪些端口
TCP 127.0.0.1:2436 127.0.0.1:9999 ESTABLISHED 22588
TCP 127.0.0.1:8080 0.0.0.0:0 LISTENING 22588
TCP 127.0.0.1:8080 127.0.0.1:2476 ESTABLISHED 22588
TCP 127.0.0.1:8080 127.0.0.1:2477 ESTABLISHED 22588
TCP 127.0.0.1:8080 127.0.0.1:2478 ESTABLISHED 22588
TCP 127.0.0.1:8080 127.0.0.1:2496 ESTABLISHED 22588
TCP 192.168.231.137:2307 111.231.95.102:443 ESTABLISHED 22588
TCP 192.168.231.137:2332 118.126.69.64:443 ESTABLISHED 22588
TCP 192.168.231.137:2400 10.23.24.4:3128 ESTABLISHED 22588
TCP 192.168.231.137:2405 10.23.24.4:3128 ESTABLISHED 22588
TCP 192.168.231.137:2459 10.23.24.4:3128 ESTABLISHED 22588
TCP 192.168.231.137:2460 10.23.24.4:3128 ESTABLISHED 22588
TCP 192.168.231.137:2461 10.23.24.4:3128 ESTABLISHED 22588
TCP 192.168.231.137:2462 10.23.24.4:3128 ESTABLISHED 22588
TCP 192.168.231.137:2463 10.23.24.4:3128 ESTABLISHED 22588
netstat -ano | findStr [端口号]
查看某个端口被哪个进程占用
netstat -ano | findStr 2436
TCP 127.0.0.1:2436 127.0.0.1:9999 ESTABLISHED 22588
TCP 127.0.0.1:9999 127.0.0.1:2436 ESTABLISHED 12308
这里pid为22588的进程和pid为12308建立了本地tcp连接,分别占用了端口2436和9999,第四列是tcp的状态,描述三次握手,四次挥手和连接完成等状态,详情可参考:https://www.cnblogs.com/jessezeng/p/5617105.html
题外话,在mac上,我们可以使用lsof -i :3000
来达到同样的效果。
taskkill
例如:
TASKKILL /IM notepad.exe
TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
TASKKILL /F /IM cmd.exe /T
TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle"
TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
TASKKILL /S system /U 域\用户名 /FI "用户名 ne NT" /IM *
TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"
cnblogs-md-editor编辑器,用Markdown写博客就用它