开发测试经常使用的Linux进程端口查询总结
1 根据程序名称查询进程
ps -aux|grep 程序名称
例如查看Jenkins程序运行的进程信息:5801
是进程的PID号
![在这里插入图片描述](https://img-blog.csdnimg.cn/a376264f08874f9bae94d5a24a5d2233.png)
2 根据进程PID查询端口
lsof -i | grep 进程pid
![在这里插入图片描述](https://img-blog.csdnimg.cn/4763c1b0719c410aa098dffa0940cda2.png)
或者
netstat -nap | grep 进程pid
![在这里插入图片描述](https://img-blog.csdnimg.cn/c45683a0c907450281e4af263f1aef97.png)
3 根据端口查询进程PID
lsof -i:端口号
或者
netstat -nap | grep 端口号
![在这里插入图片描述](https://img-blog.csdnimg.cn/f94e73345bd147bea5d59ba0f0aa17b4.png)
4 根据进程PID查询占用的目录文件
lsof -p 5801
![在这里插入图片描述](https://img-blog.csdnimg.cn/f23fb7a7e49947b0836f875c33311d31.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5pe25YCZ55qE6Ziz5YWJ,size_20,color_FFFFFF,t_70,g_se,x_16)
5 根据目录文件查询被哪些进程占用
lsof 目录
![在这里插入图片描述](https://img-blog.csdnimg.cn/d3a0182548f34998a6c7b19332068343.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP5pe25YCZ55qE6Ziz5YWJ,size_20,color_FFFFFF,t_70,g_se,x_16)