什么进程正在侦听 Solaris 上的某个端口? [英] What process is listening on a certain port on Solaris?

查看:32
本文介绍了什么进程正在侦听 Solaris 上的某个端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

于是我登录了一个Solaris盒子,尝试启动Apache,发现80端口已经有一个进程在监听,而且不是Apache.我们的盒子没有安装 lsof,所以我无法查询.我想我可以这样做:

So I log into a Solaris box, try to start Apache, and find that there is already a process listening on port 80, and it's not Apache. Our boxes don't have lsof installed, so I can't query with that. I guess I could do:

pfiles `ls /proc` | less

并寻找端口:80",但如果有人有更好的解决方案,我会全力以赴!如果我可以在没有 root 的情况下寻找聆听过程,那就更好了.我对 shell 和 C 解决方案都持开放态度;我不介意在下次出现这种情况时随身携带一个小的自定义可执行文件.

and look for "port: 80", but if anyone has a better solution, I'm all ears! Even better if I can look for the listening process without being root. I'm open to both shell and C solutions; I wouldn't mind having a little custom executable to carry with me for the next time this comes up.

更新:我说的是通用安装,我不是管理员(虽然我有超级用户访问权限),所以从免费软件磁盘安装东西不是一个选项.显然,两者都没有使用 Linux 特定的扩展来使用 fuser、netstat 或其他工具.不幸的是,到目前为止,在所有进程上运行 pfiles 似乎是最好的解决方案.如果情况仍然如此,我可能会发布一个答案,其中包含一些比上面的剪辑更高效的代码.

Updated: I'm talking about generic installs of solaris for which I am not the administrator (although I do have superuser access), so installing things from the freeware disk isn't an option. Obviously neither are using Linux-specific extensions to fuser, netstat, or other tools. So far running pfiles on all processes seems to be the best solution, unfortunately. If that remains the case, I'll probably post an answer with some slightly more efficient code that the clip above.

推荐答案

我在某处找到了这个脚本.我不记得在哪里,但它对我有用:

I found this script somewhere. I don't remember where, but it works for me:

#!/bin/ksh

line='---------------------------------------------'
pids=$(/usr/bin/ps -ef | sed 1d | awk '{print $2}')

if [ $# -eq 0 ]; then
   read ans?"Enter port you would like to know pid for: "
else
   ans=$1
fi

for f in $pids
do
   /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans"
   if [ $? -eq 0 ]; then
      echo $line
      echo "Port: $ans is being used by PID:\c"
      /usr/bin/ps -ef -o pid -o args | egrep -v "grep|pfiles" | grep $f
   fi
done
exit 0

这是原始来源:[Solaris] 哪个进程绑定到给定端口?

这篇关于什么进程正在侦听 Solaris 上的某个端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆