本文介绍了Solaris中等效的lsof -i的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I only want to show the files with network connection.

谢谢!

推荐答案

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

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:

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

注意:如,不建议在负载敏感的生产系统上运行此命令,因为该系统运行的时间敏感进程可能会发生死锁或崩溃。

Note: As documented in the warning section of the pfiles manual 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.

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

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

这篇关于Solaris中等效的lsof -i的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 01:43