如何在sunos中获取与特定端口相连的进程ID [英] how to get process id attached with particular port in sunos

查看:112
本文介绍了如何在sunos中获取与特定端口相连的进程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使进程附加有SunOS上的端口7085.我尝试了以下命令.

I am trying to get processes attached with a port 7085 on SunOS. i tried following commands.

netstat -ntlp | grep 7085没有返回任何内容

netstat -anop | grep 7085也尝试过此方法.此开关在SunO中无效

netstat -anop | grep 7085 tried this one also. This switches are not valid in SunOs

我得到以下输出.

#netstat -anop

netstat: illegal option -- o

usage: netstat [-anv] [-f address_family]

netstat [-n] [-f address_family] [-P protocol] [-g | -p | -s [interval [count]]]

netstat -m [-v] [interval [count]]

netstat -i [-I interface] [-an] [-f address_family] [interval [count]]

netstat -r [-anv] [-f address_family|filter]

netstat -M [-ns] [-f address_family]

netstat -D [-I interface] [-f address_family]

SunOS的版本是SunOS 5.10.我相信netstat是唯一可以执行此操作的命令.

The version of SunOS is SunOS 5.10. I believe netstat is the only command can do this.

netstat的确切开关是什么,它将为我提供端口附带的进程ID?

What is the exact switches for netstat which will give me the process id attached with port?

推荐答案

pfiles /proc/* 2>/dev/null | nawk '
/^[0-9]*:/ { pid=$0 }
/port: 7085$/ { printf("%s %s\n",pid,$0);}'

  • pfiles /proc/*正在检索所有进程的文件描述符详细信息
  • 2>/dev/null由于瞬态过程在此期间死亡而丢弃错误
  • 每行以数字开头,后跟冒号,将报告进程ID和详细信息,并将其存储在awk pid变量中
  • 当一行以字符串port: <portnumber>结尾(此处为7085)时,将显示相应的pid变量.
    • pfiles /proc/* is retrieving all processes file descriptors details
    • 2>/dev/null is dropping out errors due to transient processes died in the meantime
    • each line starting with a number followed by a colon reports the process id and details, it is stored in the awk pid variable
    • when a line ends with the string port: <portnumber> (here is 7085), the corresponding pid variable is displayed.
    • 注意:您需要必需的特权才能从您不拥有的进程中获取端口信息(root具有所有特权).

      Note: you need the required privilege(s) to get port information from processes you do not own (root has all privileges).

      这篇关于如何在sunos中获取与特定端口相连的进程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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