免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3817 | 回复: 2
打印 上一主题 下一主题

查看某个端口被哪个进程占用? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-01-17 12:58 |只看该作者 |倒序浏览
如题,该shell命令行怎么写??

论坛徽章:
0
2 [报告]
发表于 2004-01-17 17:46 |只看该作者

查看某个端口被哪个进程占用?

能否通过系统的命令组合来查看???

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
3 [报告]
发表于 2004-01-17 17:49 |只看该作者

查看某个端口被哪个进程占用?

还有别的办法:\r\n\r\nQ: How do I find out what process is associated with a socket connection (a network address and port number)?\r\n________________                              \r\n\r\nThere are several ways to accomplish this (lsof, pfiles, crash): \r\n\r\nA1. Use lsof  which is available on the net from several locations:\r\n  ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/lsof.tar.Z\r\n  http://www.sunfreeware.com/programlistsparc7.html#lsof64\r\n  http://www.sunfreeware.com/programlistsparc8.html#lsof\r\n  http://sunsite.doc.ic.ac.uk/sun/Solaris/freeware\r\n\r\nlsof examples:\r\n\r\nEx: netstat -a shows a connection between hodware port 36169 to ravin port 23\r\nlsof shows the PID owner of the telnet connection.\r\nexample1# netstat -a\r\n ...\r\n hodware.36169     ravin.telnet  8760      0  8760      0 ESTABLISHED\r\n\r\n # lsof -i TCP@hodware:36169\r\n COMMAND  PID   USER   FD   TYPE     DEVICE SIZE/OFF INODE NAME\r\n telnet  2686 steve    6u  inet 0x709f21e8      0t0   TCP hodware:36169->;ravin:telnet (ESTABLISHED)                              \r\n\r\nEx: netstat -an shows a connection in close_wait. \r\n\r\nlsof showd the PID and process associated with that port. \r\n\r\n\r\nexample2# netstat -an |grep CLOSE_WAIT\r\n  10.10.192.103.58046 10.10.37.122.44788 24820    0 24820      0 CLOSE_WAIT\r\n\r\n  # /usr/local/bin/lsof -i | grep 44788\r\n  netscape  27096 steve   34u  inet 0x300039bf760  0t0  TCP hodware:58046->;nop:44788 (CLOSE_WAIT)\r\n\r\n  # ps -elf |grep 27096\r\n   8 S  steve 27096 19185  0 51 20 ? 9307 ? Feb 18 pts/19  50:03 /opt/netscape/netscape\r\n\r\nexample3# netstat -an |grep 7100\r\n *.7100               *.*                0      0     0      0 LISTEN\r\n  # /usr/local/bin/lsof -i TCP:7100\r\n  COMMAND  PID USER   FD   TYPE        DEVICE SIZE/OFF NODE NAME\r\n  inetd   4512 root   33u  inet 0x300014ef750      0t0  TCP *:fs (LISTEN)            \r\n\r\nto list all ports with a process: \r\n\r\nexample4# lsof -i -P | grep snmpdx \r\n\r\nsnmpdx 5771 root 4u inet 0x60f5add0 0t0 UDP *:161 (Idle) \r\n\r\nsnmpdx 5771 root 5u inet 0x60ded648 0t0 UDP *:38725 (Idle) \r\n\r\nsnmpdx 5771 root 6u inet 0x61101358 0t0 UDP *:38726 (Idle) \r\n\r\n\r\n# \r\n\r\nto list all TCP connections\r\nexample5# /usr/local/bin/lsof -i TCP                                                               \r\n\r\n\r\nnote: lsof is not supported by Sun Enterprise Services, so you are on your own\r\n  as far as obtaining it, compiling it and running it and any problems you may encounter.\r\n\r\n________________\r\nA2. or use Solaris 8 pfiles\r\n Solaris 8 added new feature to display socketname using pfiles tool.\r\n see proc(1) and below example.\r\n\r\nsolaris 8 pfiles methods :\r\n example5# cd /proc ; /usr/proc/binpfiles * | egrep \"^[0-9]|sockname\" | more\r\n ....\r\n 968:    in.ftpd\r\n     sockname: AF_INET6 ::ffff:10.1.1.77  port: 21\r\n     sockname: AF_INET6 ::ffff:10.1.1.77  port: 21\r\nor \r\n example6# su\r\n # cd /proc\r\n # /usr/proc/bin/pfiles * >; /tmp/pfiles.out\r\n # vi /tmp/pfiles.out\r\n /port: PortOfInterest\r\n ?^[0-9]\r\n\r\n________________\r\n\r\nA3. if you are resourceful enough, use adb or crash to trace down each open file descriptor\r\nthat a process owns, but there is no way to go in the reverse direction so this would be extremely\r\ntime consuming and tedious.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP