美文网首页Linux
Mac/linux获取监听知道进程的pid

Mac/linux获取监听知道进程的pid

作者: 青山淼淼 | 来源:发表于2020-12-06 12:24 被阅读0次
mac获取指定端口号进程
  • 因为在执行php命令的时候发现端口已经被占用。提示报错信息Address already in use

可以执行以下命令找到对应进程 。

lsof -n -i:prot | grep LISTEN

如查找9001端口被哪个进程占用!

lsof -n -i:9001 | grep LISTEN

输出以下内容:

php     10412 liubo    3u  IPv4 0x9c44a369a4cebe0f      0t0  TCP *:etlservicemgr (LISTEN)
  • CentOS服务器
    比如想知道 80端口被那个进程占用:
[root@iz2ze73gz63uq3qjgvd24az ~]# lsof -n -i:80 | grep LISTEN
-bash: lsof: 未找到命令

安装 lsof 插件 ->yum install lsof

[root@iz2ze73gz63uq3qjgvd24az ~]# lsof -n -i:80 | grep LISTEN
docker-pr 2446 root    4u  IPv6  31336      0t0  TCP *:http (LISTEN)

相关文章

网友评论

    本文标题:Mac/linux获取监听知道进程的pid

    本文链接:https://www.haomeiwen.com/subject/wndowktx.html