菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
198
0

利用netstat和tasklist查看PC的端口占用情况 及80端口被占用

原创
05/13 14:22
阅读数 48239

  经常,我们在启动应用的时候发现系统需要的端口被别的程序占用,如何知道谁占有了我们需要的端口?

1、Windows平台
在windows命令行窗口下执行:

E:\oracle\ora92\bin>netstat -ano |find ":80"
TCP 172.18.2.56:3311 172.18.40.3:80 ESTABLISHED 3704
TCP 172.18.2.56:3319 172.18.65.7:80 ESTABLISHED 3704
TCP 172.18.2.56:4641 172.18.40.3:80 ESTABLISHED 3704
TCP 172.18.2.56:4734 172.18.65.7:80 ESTABLISHED 3704
TCP 172.18.2.56:4847 172.18.40.3:80 ESTABLISHED 3560
TCP 172.18.2.56:4848 172.18.40.3:80 ESTABLISHED 3560

有个PID为3560的进程占用了80端口,继续执行下面命令:
E:\oracle\ora92\bin>tasklist /svc |find "3560"
firefox.exe 3560 Console 0 147,564 K

可以发现是firefox的进程,并可看到占用的内存大小。

附netstat命令参数效果的对比:
E:\oracle\ora92\bin>netstat -a |find ":8080"
TCP wanhua:8080 0.0.0.0:0 LISTENING

E:\oracle\ora92\bin>netstat -an |find ":8080"
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING

E:\oracle\ora92\bin>netstat -ano |find ":8080"
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING

win7无法启动apache:

最近在WIN7中安装XAMPP,无法启动apache,显示的log为: 

20:41:12  [Apache] Error: Apache shutdown unexpectedly. 
20:41:12  [Apache] This may be due to a blocked port, missing dependencies, 
20:41:12  [Apache] improper privileges, a crash, or a shutdown by another method. 
20:41:12  [Apache] Check the "/xampp/apache/logs/error.log" file 
20:41:12  [Apache] and the Windows Event Viewer for more clues 

通过运行apache/bin/httpd.exe 打印如下log: 
(OS 10048)通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 : make_sock: could not bind to address 0.0.0.0:443 

也就是443端口被占用,apache无法监听443端口,该如何解决呢? 

最直接的方法是关闭占用443端口的进程: 
1.通过cmd中打印tasklist,查找占用443端口的进程。 
2.taskkill /pid 端口号 杀掉此进程,XAMPP重启apache即可。

 

发表评论

0/200
198 点赞
0 评论
收藏