Linux 等效于 Solaris 中的 lsof -i

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20670400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:40:23  来源:igfitidea点击:

Equivalent lsof -i in Solaris

linuxunixcommandsolarisequivalent

提问by Alberto

I have a fast question. I want to know what is the losf -iequivalent command in a Solaris system.

我有一个快速的问题。我想知道losf -iSolaris 系统中的等效命令是什么。

I only want to show the files with network connection.

我只想显示具有网络连接的文件。

Thank you!!

谢谢!!

采纳答案by jlliagre

Here is a shell script that list all processes having open TCP or UDP ports on Solaris, you can limit it to a given port number by passing it as an argument:

这是一个 shell 脚本,它列出了 Solaris 上所有具有开放 TCP 或 UDP 端口的进程,您可以通过将其作为参数传递来将其限制为给定的端口号:

pfiles /proc/* 2>/dev/null | nawk -v port= '
    /^[0-9]/ { cmd=; type="unknown"; continue }
     == "SOCK_STREAM" { type="tcp" }
     == "SOCK_DGRAM" { type="udp" }
     ~ "AF_INET" { if((port!="")&&(!=port)) continue;
                      if(cmd!="") { printf("%s\n",cmd); cmd="" }
                      printf("    %s:%s/%s\n",,,type); }'

Note: As documented in the warning section of the pfilesmanual page, it is not recommended to run this command on a heavily loaded production system with a time sensitive process running as deadlocks or crashes might happen.

注意:如pfiles手册页的警告部分所述,不建议在负载重的生产系统上运行此命令,因为可能会发生死锁或崩溃。

Note #2: The previous warning doesn't apply to the last update of Solaris (Oracle Solaris 11.4) because pfilesno more suspend the monitored process(es). It now just uses ad hoc /proc pseudo files.

注意 #2:之前的警告不适用于 Solaris (Oracle Solaris 11.4) 的最后一次更新,因为pfiles不再暂停受监视的进程。它现在只使用临时 /proc 伪文件。

回答by Tharanga Abeyseela

you can try pfiles,fuser. you can install lsof on solaris.

你可以试试pfiles,fuser。你可以在solaris上安装lsof。

http://andriigrytsenko.net/2010/08/lsof-installation-on-solaris-10/

http://andriigrytsenko.net/2010/08/lsof-installation-on-solaris-10/

回答by peterh

As of Solaris 11.2 this type of information is now available directly in the netstatcommand (-uoption) so you don't have to use the pfileshack for the purpose or use the lsoftool. Personally I've always wondered why this information could not be part of the netstatoutput so glad to see that'll finally be the case.

从 Solaris 11.2 开始,这种类型的信息现在可以直接在netstat命令(-u选项)中使用,因此您不必pfiles为此目的使用 hack 或使用该lsof工具。就我个人而言,我一直想知道为什么这些信息不能成为netstat输出的一部分,很高兴看到最终会如此。

There's a nice blog from Oracle on the topic.

Oracle一篇关于该主题不错的博客

(caveat: at the time of writing v11.2 is in beta but fully disclosed as to the contents / new features)

(警告:在撰写本文时,v11.2 处于测试阶段,但已完全披露内容/新功能)