首页  

linux下找出占用指定端口的进程     所属分类 linux 浏览量 1287
linux下找出占用指定端口的进程


通过 进程找端口  通过端口找进程 都可以用 netstat 

 ps aux|grep exporter

nginx    3450781  0.0  0.2 314788 11628 ?        Sl   3月13   2:28 ./nginx_base_exporter -nginx.scrape_uri http://localhost:8999/nginx_status
nginx    3450782  0.0  0.4 388696 18568 ?        Sl   3月13   0:15 ./nginx_exporter --nginx.scrape_uri=http://localhost:8999/status/format/json


 sudo netstat -anltp |grep 3450781
tcp6       0      0 :::9113                 :::*                    LISTEN      3450781/./nginx_bas 

 sudo netstat -anltp |grep 3450782
tcp6       0      0 :::9913                 :::*                    LISTEN      3450782/./nginx_exp 


 sudo netstat -anltp |grep 9913
tcp6       0      0 :::9913                 :::*                    LISTEN      3450782/./nginx_exp 

sudo netstat -anltp |grep 9113
tcp6       0      0 :::9113                 :::*                    LISTEN      3450781/./nginx_bas 



两种方式 lsof 和 netstat lsof -i:端口号 lsof -i:3000 | wc -l 109 sudo lsof -i:3000 | wc -l 117 加上 sudo 才能看到 全部 netstat -tunpl | grep 端口号 -a :all,表示列出所有的连接 -t :tcp,列出tcp协议的服务 -u :udp,列出udp协议的服务 -n :port number, 用端口号来显示 -l :listening,监听服务 -p :program,列出应用进程PID netstat -tunlp | grep 3000 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN - 不加 sudo 不会显示 PID sudo netstat -tunlp | grep 3000 tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN 134103/asd 加上 sudo 才能看到全部信息

上一篇     下一篇
go语言defer机制

简单的清理脚本实战

prometheus配置

jvm设置滚动记录GC日志

基于数据库的分布式锁设计

prometheus集成grafana实现可视化