• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-6-08 22:43 | 作者: seanhe | 来源: | 查看: 330次 | 进入软件测试论坛讨论

领测软件测试网
如题,该shell命令行怎么写??

【发表回复】【查看CU论坛原帖】【添加到收藏夹】【关闭】
 C.Arthur 回复于:2004-01-17 13:37:35
lsof查看
需要安装

 yetiwolf 回复于:2004-01-17 17:46:51
能否通过系统的命令组合来查看???

 beginner-bj 回复于:2004-01-17 17:49:38
还有别的办法:

Q: How do I find out what process is associated with a socket connection (a network address and port number)?
________________                              

There are several ways to accomplish this (lsof, pfiles, crash): 

A1. Use lsof  which is available on the net from several locations:
  ftp://vic.cc.purdue.edu/pub/tools/unix/lsof/lsof.tar.Z
  http://www.sunfreeware.com/programlistsparc7.html#lsof64
  http://www.sunfreeware.com/programlistsparc8.html#lsof
  http://sunsite.doc.ic.ac.uk/sun/Solaris/freeware

lsof examples:

Ex: netstat -a shows a connection between hodware port 36169 to ravin port 23
lsof shows the PID owner of the telnet connection.
example1# netstat -a
 ...
 hodware.36169     ravin.telnet  8760      0  8760      0 ESTABLISHED

 # lsof -i TCP@hodware:36169
 COMMAND  PID   USER   FD   TYPE     DEVICE SIZE/OFF INODE NAME
 telnet  2686 steve    6u  inet 0x709f21e8      0t0   TCP hodware:36169->ravin:telnet (ESTABLISHED)                              

Ex: netstat -an shows a connection in close_wait. 

lsof showd the PID and process associated with that port. 


example2# netstat -an |grep CLOSE_WAIT
  10.10.192.103.58046 10.10.37.122.44788 24820    0 24820      0 CLOSE_WAIT

  # /usr/local/bin/lsof -i | grep 44788
  netscape  27096 steve   34u  inet 0x300039bf760  0t0  TCP hodware:58046->nop:44788 (CLOSE_WAIT)

  # ps -elf |grep 27096
   8 S  steve 27096 19185  0 51 20 ? 9307 ? Feb 18 pts/19  50:03 /opt/netscape/netscape

example3# netstat -an |grep 7100
 *.7100               *.*                0      0     0      0 LISTEN
  # /usr/local/bin/lsof -i TCP:7100
  COMMAND  PID USER   FD   TYPE        DEVICE SIZE/OFF NODE NAME
  inetd   4512 root   33u  inet 0x300014ef750      0t0  TCP *:fs (LISTEN)            

to list all ports with a process: 

example4# lsof -i -P | grep snmpdx 

snmpdx 5771 root 4u inet 0x60f5add0 0t0 UDP *:161 (Idle) 

snmpdx 5771 root 5u inet 0x60ded648 0t0 UDP *:38725 (Idle) 

snmpdx 5771 root 6u inet 0x61101358 0t0 UDP *:38726 (Idle) 




to list all TCP connections
example5# /usr/local/bin/lsof -i TCP                                                               


note: lsof is not supported by Sun Enterprise Services, so you are on your own
  as far as obtaining it, compiling it and running it and any problems you may encounter.

________________
A2. or use Solaris 8 pfiles
 Solaris 8 added new feature to display socketname using pfiles tool.
 see proc(1) and below example.

solaris 8 pfiles methods :
 example5# cd /proc ; /usr/proc/binpfiles * | egrep "^[0-9]|sockname" | more
 ....
 968:    in.ftpd
     sockname: AF_INET6 ::ffff:10.1.1.77  port: 21
     sockname: AF_INET6 ::ffff:10.1.1.77  port: 21
or 
 example6# su
 # cd /proc
 # /usr/proc/bin/pfiles * > /tmp/pfiles.out
 # vi /tmp/pfiles.out
 /port: PortOfInterest
 ?^[0-9]

________________

A3. if you are resourceful enough, use adb or crash to trace down each open file descriptor
that a process owns, but there is no way to go in the reverse direction so this would be extremely
time consuming and tedious.

 peng 回复于:2004-01-17 18:08:37
#netstat -an |grep point 可以吗?
以前用的一个,忘了。。:(

 calltomxy 回复于:2004-01-17 19:16:20
不错

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网