Linux根据端口号查看进程PID
0. 命令安装
# CentOS
yum install lsof2
yum install net-tools # [On CentOS/RHEL]
1、命令 lsof
,以查找占用端口 80 为例,用法如下:
$[root@localhost nginx]# lsof -i:80
# 以上为没有进程占用80端口,
$[root@localhost sbin]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 8246 root 6u IPv4 64233 0t0 TCP *:http (LISTEN)
nginx 8247 nobody 6u IPv4 64233 0t0 TCP *:http (LISTEN)
以上为进程ID为 8246 和 8247 的 nginx
应用,占用 80 端口。
2、命令netstat,以查找占用 80 端口为例,用法如下:
$[root@localhost sbin]# netstat -nlp|grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8246/nginx
3、命令 ps
,可以查看已知进程PID的执行目录的详细信息
$[root@localhost sbin]# ps -ef | grep 8246
root 8246 1 0 14:56 ? 00:00:00 nginx: master process ./nginx
nobody 8247 8246 0 14:56 ? 00:00:00 nginx: worker process
root 8461 2679 0 15:26 pts/1 00:00:00 grep 8246
$[root@localhost sbin]# ps -x | grep 8246
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
8246 ? Ss 0:00 nginx: master process ./nginx
8463 pts/1 S+ 0:00 grep 8246
# netstat 去检测 nacos 2.x 版本的3个必须端口
netstat -tunlp | grep 8848
netstat -tunlp | grep 9848
netstat -tunlp | grep 9849
# 正确输出
# tcp 0 0 0.0.0.0:8848 0.0.0.0:* LISTEN 1/java
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· 分享4款.NET开源、免费、实用的商城系统
· 解决跨域问题的这6种方案,真香!
· 一套基于 Material Design 规范实现的 Blazor 和 Razor 通用组件库
· 5. Nginx 负载均衡配置案例(附有详细截图说明++)
2021-05-19 【每日一题】29.maze (BFS 进阶)
2021-05-19 2016年第七届 蓝桥杯C组 C/C++决赛题解
2021-05-19 2016年第七届 蓝桥杯A组 C/C++决赛题解
2020-05-19 Floyd算法C++实现与模板题应用
2020-05-19 POJ:Arbitrage (搜索,汇率换算是否赚?)
2020-05-19 POJ:3660 Cow Contest (传递闭包 + Floyd)