Loading... > 总结一下日常工作学习中常用的查询占用端口、PID相关命令。主要有命令 ps、lsof、netstat 等命令。 ## ps `ps -ef` 或者 `ps aux` 根据命令(IntelliJIDEALicenseServer)搜索 PID(17107) ```shell $ ps -ef | grep IntelliJIDEALicenseServer | grep -v "grep" 501 17017 12203 0 10:01上午 ttys000 0:00.02 IntelliJIDEALicenseServer -p 21014 ``` ## lsof 根据 PID(17107)搜索占用端口(21014) ```bash $ lsof -p 17017 -nP | grep TCP COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME IntelliJI 17017 ehlxr 3u IPv4 0xc0df10496212b0e3 0t0 TCP *:21014 (LISTEN) # 或者使用 $ lsof -nP -iTCP -sTCP:LISTEN | grep 17017 ``` > * -n 表示不显示主机名 > * -P 表示不显示端口俗称 <!--more--> 根据端口(21014)搜索 PID(17107) ```bash $ lsof -i:21014 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME IntelliJI 17017 ehlxr 3u IPv4 0xc0df10496212b0e3 0t0 TCP *:21014 (LISTEN) ``` ## netstat **仅 Linux 系统下好使,Mac 下无效** 端口(21017),PID(1847) ```bash $ netstat -antlp | grep IntelliJIDEA tcp 0 0 0.0.0.0:21017 0.0.0.0:* LISTEN 1847/./IntelliJIDEA ``` — The End — Last modification:August 30th, 2018 at 07:28 pm © 允许规范转载 Support If you think my article is useful to you, please feel free to appreciate ×Close Appreciate the author Sweeping payments Pay by AliPay Pay by WeChat