Linux下查看某个进程打开的文件数-losf工具常用参数介绍

                                           作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

  在linux操作系统中,一切皆文件。通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件。比如说传输控制协议 (TCP) 和用户数据报协议 (UDP) 套接字等。有时候我们可能需要统计一下那个进程占用了那类文件,或者该进程总共打开的文件数等等,此时我们就需要一个工具帮我们查看相应的信息啦,它就是本片博客的主人公-lsof。

  

一.losf是个什么玩意?

1>.losf是个

  如上所述,在Linux中,一切皆文件。lsof(list open files)是一个列出当前系统打开文件的工具。

2>.losf可以列出被进程所打开的文件的信息

  系统在后台都为该应用程序分配了一个文件描述符,无论这个文件的本质如何,该文件描述符为应用程序与基础操作系统之间的交互提供了通用接口。因为应用程序打开文件的描述符列表提供了大量关于这个应用程序本身的信息,因此通过lsof工具能够查看这个列表对系统监测以及排错将是很有帮助的。被打开的文件可以是:

.普通的文件;
.目录  
.网络文件系统的文件
.字符设备文件  
.(函数)共享库  
.管道,命名管道 
.符号链接
.底层的socket字流,网络socket,unix域名socket
.还有一些其他的文件我这里就不一一列举了,在linux操作系统中,一切皆文件。

2>.安装losf工具包

[root@yinzhengjie ~]# yum -y install lsof
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package lsof.x86_64 :4.87-.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ====================================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================================
Installing:
lsof x86_64 4.87-.el7 base k Transaction Summary
====================================================================================================================================================================
Install Package Total download size: k
Installed size: k
Downloading packages:
lsof-4.87-.el7.x86_64.rpm | kB ::
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : lsof-4.87-.el7.x86_64 /
Verifying : lsof-4.87-.el7.x86_64 / Installed:
lsof.x86_64 :4.87-.el7 Complete!
[root@yinzhengjie ~]#

[root@yinzhengjie ~]# yum -y install lsof

3>.查看losf命令的帮助信息

[root@yinzhengjie ~]# lsof -h
lsof 4.87
latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
[-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
-?|-h list help -a AND selections (OR) -b avoid kernel blocks
-c c cmd c ^c /c/[bix] +c w COMMAND width () +d s dir s files
-d s select by FD set +D D dir D tree *SLOW?* +|-e s exempt s *RISKY*
-i select IPv[] files -K list tasKs (threads) -l list UID numbers
-n no host names -N select NFS files -o list file offset
-O no overhead *RISKY* -P no port names -R list paRent PID
-s list file size -t terse listing -T disable TCP/TPI info
-U select Unix socket -v list version info -V verbose search
+|-w Warnings (+) -X skip TCP&UDP* files -Z Z context [Z]
-- end option scan
+f|-f +filesystem or -file names +|-f[gG] flaGs
-F [f] select fields; -F? for help
+|-L [l] list (+) suppress (-) link counts < l ( = all; default = )
+m [m] use|create mount supplement
+|-M portMap registration (-) -o o o 0t offset digits ()
-p s exclude(^)|select PIDs -S [t] t second stat timeout ()
-T qs TCP/TPI Q,St (s) info
-g [s] exclude(^)|select and print process group IDs
-i i select by IPv[] address: [][proto][@host|addr][:svc_list|port_list]
+|-r [t[m<fmt>]] repeat every t seconds (); + until no files, - forever.
An optional suffix to t is m<fmt>; m must separate t from <fmt> and
<fmt> is an strftime() format for the marker line.
-s p:s exclude(^)|select protocol (p = TCP|UDP) states by name(s).
-u s exclude(^)|select login|UID set s
-x [fl] cross over +d|+D File systems or symbolic Links
names select named files or files on named file systems
Anyone can list all files; /dev warnings disabled; kernel ID check disabled.
[root@yinzhengjie ~]#

  大家也看到了帮助信息,参数还挺多的,不过大家不要慌,其实工作中我们用不了几个参数,我常用的几个参数如下:

-a : 结果进行“与”运算(而不是“或”)
-l : 在输出显示用户ID而不是用户名
-h : 获得帮助
-t : 仅获取进程ID
-U : 获取UNIX套接口地址
-F : 格式化输出结果,用于其它命令。可以通过多种方式格式化,如-F pcfn(用于进程id、命令名、文件描述符、文件名,并以空终止)

  光说不练假把式,接下来,我们就来搞点事情,把一些常用参数的案例来耍一耍。

二.lsof使用案例

1>.统计操作系统所有打开的文件(如果不加任何参数,就会打开所有被打开的文件,建议加上一下参数来具体定位)

[root@yinzhengjie ~]# hostname
yinzhengjie
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# hostname -i
10.1.2.105
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof | wc -l  #突然发现我的虚拟机还听可以的,竟然能打开33万的连接数呢! [root@yinzhengjie ~]#

2>.递归查看某个目录正在使用的文件信息

[root@yinzhengjie ~]# lsof +D /soft/
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java hdfs txt REG , /soft/jdk1..0_131/bin/java
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/charsets.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/resources.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libsunec.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjaas_unix.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/jce.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnio.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libmanagement.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnet.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/rt.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libzip.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjava.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libverify.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/server/libjvm.so
java hdfs mem REG , /soft/jdk1..0_131/lib/amd64/jli/libjli.so
java hdfs 3r REG , /soft/jdk1..0_131/jre/lib/rt.jar
java hdfs 166r REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java hdfs 178r REG , /soft/jdk1..0_131/jre/lib/jce.jar
java hdfs 181r REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java hdfs 182r REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java hdfs 188r REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java hdfs 201r REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java hdfs 202r REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java hdfs 229r REG , /soft/jdk1..0_131/jre/lib/resources.jar
java hdfs 234r REG , /soft/jdk1..0_131/jre/lib/charsets.jar
java httpfs txt REG , /soft/jdk1..0_131/bin/java
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjaas_unix.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libsunec.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libawt_headless.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libawt.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnio.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnet.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libmanagement.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/jce.jar
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/rt.jar
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libzip.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjava.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libverify.so
java httpfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/server/libjvm.so
java httpfs mem REG , /soft/jdk1..0_131/lib/amd64/jli/libjli.so
java httpfs 3r REG , /soft/jdk1..0_131/jre/lib/rt.jar
java httpfs 30r REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java httpfs 31r REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java httpfs 32r REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java httpfs 33r REG , /soft/jdk1..0_131/jre/lib/jce.jar
java httpfs 34r REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java httpfs 35r REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java httpfs 42r REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java hdfs txt REG , /soft/jdk1..0_131/bin/java
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjaas_unix.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnio.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libmanagement.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnet.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/rt.jar
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libzip.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjava.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/libverify.so
java hdfs mem REG , /soft/jdk1..0_131/jre/lib/amd64/server/libjvm.so
java hdfs mem REG , /soft/jdk1..0_131/lib/amd64/jli/libjli.so
java hdfs 3r REG , /soft/jdk1..0_131/jre/lib/rt.jar
java hdfs 180r REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java hdfs 187r REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java hdfs 191r REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java mapred txt REG , /soft/jdk1..0_131/bin/java
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjaas_unix.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libmanagement.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnio.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libsunec.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/jce.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnet.so
java mapred mem REG , /soft/jdk1..0_131/lib/tools.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/rt.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libzip.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjava.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libverify.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/server/libjvm.so
java mapred mem REG , /soft/jdk1..0_131/lib/amd64/jli/libjli.so
java mapred 3r REG , /soft/jdk1..0_131/jre/lib/rt.jar
java mapred 5r REG , /soft/jdk1..0_131/lib/tools.jar
java mapred 132r REG , /soft/jdk1..0_131/jre/lib/jce.jar
java mapred 133r REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java mapred 140r REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java mapred 141r REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java mapred 154r REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java yarn txt REG , /soft/jdk1..0_131/bin/java
java yarn mem REG , /soft/jdk1..0_131/jre/lib/resources.jar
java yarn mem REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java yarn mem REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java yarn mem REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java yarn mem REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java yarn mem REG , /soft/jdk1..0_131/jre/lib/amd64/libsunec.so
java yarn mem REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java yarn mem REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java yarn mem REG , /soft/jdk1..0_131/jre/lib/jce.jar
java yarn mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjaas_unix.so
java yarn mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnio.so
java yarn mem REG , /soft/jdk1..0_131/jre/lib/amd64/libmanagement.so
java yarn mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnet.so
java yarn mem REG , /soft/jdk1..0_131/jre/lib/rt.jar
java yarn mem REG , /soft/jdk1..0_131/jre/lib/amd64/libzip.so
java yarn mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjava.so
java yarn mem REG , /soft/jdk1..0_131/jre/lib/amd64/libverify.so
java yarn mem REG , /soft/jdk1..0_131/jre/lib/amd64/server/libjvm.so
java yarn mem REG , /soft/jdk1..0_131/lib/amd64/jli/libjli.so
java yarn 3r REG , /soft/jdk1..0_131/jre/lib/rt.jar
java yarn 163r REG , /soft/jdk1..0_131/jre/lib/jce.jar
java yarn 164r REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java yarn 174r REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java yarn 175r REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java yarn 176r REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java yarn 227r REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java yarn 228r REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java yarn 229r REG , /soft/jdk1..0_131/jre/lib/resources.jar
java mapred txt REG , /soft/jdk1..0_131/bin/java
java mapred mem REG , /soft/jdk1..0_131/jre/lib/resources.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjaas_unix.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnio.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libsunec.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/jce.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libmanagement.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnet.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/rt.jar
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libzip.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjava.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/libverify.so
java mapred mem REG , /soft/jdk1..0_131/jre/lib/amd64/server/libjvm.so
java mapred mem REG , /soft/jdk1..0_131/lib/amd64/jli/libjli.so
java mapred 3r REG , /soft/jdk1..0_131/jre/lib/rt.jar
java mapred 162r REG , /soft/jdk1..0_131/jre/lib/jce.jar
java mapred 163r REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java mapred 170r REG , /soft/jdk1..0_131/jre/lib/ext/sunec.jar
java mapred 171r REG , /soft/jdk1..0_131/jre/lib/ext/sunjce_provider.jar
java mapred 172r REG , /soft/jdk1..0_131/jre/lib/ext/sunpkcs11.jar
java mapred 205r REG , /soft/jdk1..0_131/jre/lib/ext/cldrdata.jar
java mapred 206r REG , /soft/jdk1..0_131/jre/lib/ext/localedata.jar
java mapred 207r REG , /soft/jdk1..0_131/jre/lib/resources.jar
java spark txt REG , /soft/jdk1..0_131/bin/java
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnio.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjaas_unix.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnet.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libmanagement.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/rt.jar
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libzip.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjava.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libverify.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/server/libjvm.so
java spark mem REG , /soft/jdk1..0_131/lib/amd64/jli/libjli.so
java spark 3r REG , /soft/jdk1..0_131/jre/lib/rt.jar
java spark 333r REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java spark txt REG , /soft/jdk1..0_131/bin/java
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnio.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/jsse.jar
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjaas_unix.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libnet.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libmanagement.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/rt.jar
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libzip.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libjava.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/libverify.so
java spark mem REG , /soft/jdk1..0_131/jre/lib/amd64/server/libjvm.so
java spark mem REG , /soft/jdk1..0_131/lib/amd64/jli/libjli.so
java spark 3r REG , /soft/jdk1..0_131/jre/lib/rt.jar
java spark 283r REG , /soft/jdk1..0_131/jre/lib/jsse.jar
[root@yinzhengjie ~]#

[root@yinzhengjie ~]# lsof +D /soft/                #使用了+D,对应目录下的所有子目录和文件都会被列出

3>.查看某个文件正在被谁使用

[root@yinzhengjie ~]# lsof /soft/jdk1..0_131/bin/java                      #如果没有输出的话,则说明没有任何用户使用当前文件哟!
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java hdfs txt REG , /soft/jdk1..0_131/bin/java
java httpfs txt REG , /soft/jdk1..0_131/bin/java
java hdfs txt REG , /soft/jdk1..0_131/bin/java
java mapred txt REG , /soft/jdk1..0_131/bin/java
java yarn txt REG , /soft/jdk1..0_131/bin/java
java mapred txt REG , /soft/jdk1..0_131/bin/java
java spark txt REG , /soft/jdk1..0_131/bin/java
java spark txt REG , /soft/jdk1..0_131/bin/java
[root@yinzhengjie ~]# 字段补充说明,lsof输出各列信息的意义如下:
COMMAND:进程的名称 PID:进程标识符 USER:进程所有者 FD:文件描述符,应用程序通过文件描述符识别该文件。如cwd、txt等 TYPE:文件类型,如DIR、REG等 DEVICE:指定磁盘的名称 SIZE:文件的大小 NODE:索引节点(文件在磁盘上的标识) NAME:打开文件的确切名称 FD 列中的文件描述符cwd 值表示应用程序的当前工作目录,这是该应用程序启动的目录,除非它本身对这个目录进行更改,txt 类型的文件是程序代码,如应用程序二进制文件本身或共享库,如上列表中显示的 /sbin/init 程序。 对文件描述符FD的补充说明:
其次数值表示应用程序的文件描述符,这是打开该文件时返回的一个整数。如上的最后一行文件/dev/initctl,其文件描述符为 。u 表示该文件被打开并处于读取/写入模式,而不是只读 ® 或只写 (w) 模式。同时还有大写 的W 表示该应用程序具有对整个文件的写锁。该文件描述符用于确保每次只能打开一个应用程序实例。初始打开每个应用程序时,都具有三个文件描述符,从 到 ,分别表示标准输入、输出和错误流。所以大多数应用程序所打开的文件的 FD 都是从 开始。与 FD 列相比,Type 列则比较直观。文件和目录分别称为 REG 和 DIR。而CHR 和 BLK,分别表示字符和块设备;或者 UNIX、FIFO 和 IPv4,分别表示 UNIX 域套接字、先进先出 (FIFO) 队列和网际协议 (IP) 套接字。

4>.列出某个程序所打开的文件信息

[root@yinzhengjie ~]# lsof -c java | wc -l           #我们统计一下java进程打开的文件数

[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof | grep java | wc -l       #你会发现下面的这个参数这个文件打开文件数要比上面的多得多呢! [root@yinzhengjie ~]#

5>.列出多个程序多打开的文件信息

[root@yinzhengjie ~]# lsof -c java | wc -l

[root@yinzhengjie ~]# lsof -c mysql | wc -l

[root@yinzhengjie ~]# lsof -c java -c mysql | wc -l 

[root@yinzhengjie ~]# 

6>.列出某个用户通过某个命令打开的文件数

[root@yinzhengjie ~]# lsof -u root -c mysql |wc -l

[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -u hdfs -c mysql |wc -l [root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -u hive -c mysql |wc -l [root@yinzhengjie ~]#

7>.使用-i显示所有连接(其功能并不比netstat -untalp功能弱!)

[root@yinzhengjie ~]# lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
chronyd chrony 1u IPv4 0t0 UDP localhost:
chronyd chrony 2u IPv6 0t0 UDP localhost:
chronyd chrony 4u IPv4 0t0 UDP node105.yinzhengjie.org.cn:->119.28.183.184:ntp
sshd root 3u IPv4 0t0 TCP *:ssh (LISTEN)
sshd root 4u IPv6 0t0 TCP *:ssh (LISTEN)
httpd root 4u IPv6 0t0 TCP *:http (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
mysqld mysql 13u IPv6 0t0 TCP *:mysql (LISTEN)
mysqld mysql 86u IPv6 0t0 TCP node105.yinzhengjie.org.cn:mysql->10.19.104.189: (ESTABLISHED)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
master root 13u IPv4 0t0 TCP localhost:smtp (LISTEN)
master root 14u IPv6 0t0 TCP localhost:smtp (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
sshd root 3u IPv4 0t0 TCP node105.yinzhengjie.org.cn:ssh->10.19.104.189: (ESTABLISHED)
cmf-agent root 8u IPv4 0t0 TCP localhost:->localhost: (ESTABLISHED)
cmf-agent root 12u IPv4 0t0 TCP node105.yinzhengjie.org.cn:cslistener (LISTEN)
cmf-agent root 13u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
cmf-agent root 15u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
cmf-agent root 16u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
python root 4u IPv4 0t0 TCP localhost: (LISTEN)
python root 6u IPv4 0t0 TCP localhost:->localhost: (ESTABLISHED)
python2. root 7u IPv4 0t0 TCP *: (LISTEN)
python2. root 8u IPv4 0t0 TCP *:vop (LISTEN)
python2. root 10u IPv6 0t0 TCP *: (LISTEN)
python2. root 11u IPv6 0t0 TCP *: (LISTEN)
python2. root 12u IPv4 0t0 UDP *:
python2. root 13u IPv6 0t0 UDP *:
python2. root 14u IPv4 0t0 TCP localhost: (LISTEN)
java hdfs 173u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java hdfs 179u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 180u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node103.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 189u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node104.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 190u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 191u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 194u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node104.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 206u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system (LISTEN)
java hdfs 216u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc (LISTEN)
java hdfs 227u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 230u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node102.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 238u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node102.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 239u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn: (ESTABLISHED)
java httpfs 44u IPv4 0t0 TCP *:scotty-ft (LISTEN)
java httpfs 46u IPv4 0t0 TCP localhost:sua (LISTEN)
java hdfs 164u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:oa-system (ESTABLISHED)
java hdfs 169u IPv4 0t0 TCP node105.yinzhengjie.org.cn:qbdb (LISTEN)
java hdfs 192u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn:eforward (ESTABLISHED)
java hdfs 193u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 142u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client (LISTEN)
java mapred 153u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 155u IPv4 0t0 TCP *: (LISTEN)
java mapred 169u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 170u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node104.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 171u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node103.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 172u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node102.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 161u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 177u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 188u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 198u IPv4 0t0 TCP node105.yinzhengjie.org.cn:pro-ed (LISTEN)
java yarn 208u IPv4 0t0 TCP node105.yinzhengjie.org.cn:radan-http (LISTEN)
java yarn 212u IPv4 0t0 TCP node105.yinzhengjie.org.cn:mindprint (LISTEN)
java yarn 222u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node102.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 223u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 224u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node104.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 180u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 191u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 195u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 211u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java spark 342u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
java spark 347u IPv4 0t0 TCP *: (LISTEN)
java spark 292u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
java spark 297u IPv4 0t0 TCP *: (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
sshd root 3u IPv4 0t0 TCP node105.yinzhengjie.org.cn:ssh->10.19.104.189: (ESTABLISHED)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -i | wc -l [root@yinzhengjie ~]#
[root@yinzhengjie ~]# netstat -untalp | wc -l [root@yinzhengjie ~]#

[root@yinzhengjie ~]# lsof -i

[root@yinzhengjie ~]# lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
chronyd chrony 2u IPv6 0t0 UDP localhost:
sshd root 4u IPv6 0t0 TCP *:ssh (LISTEN)
httpd root 4u IPv6 0t0 TCP *:http (LISTEN)
mysqld mysql 13u IPv6 0t0 TCP *:mysql (LISTEN)
mysqld mysql 86u IPv6 0t0 TCP node105.yinzhengjie.org.cn:mysql->10.19.104.189: (ESTABLISHED)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
master root 14u IPv6 0t0 TCP localhost:smtp (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
python2. root 10u IPv6 0t0 TCP *: (LISTEN)
python2. root 11u IPv6 0t0 TCP *: (LISTEN)
python2. root 13u IPv6 0t0 UDP *:
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
[root@yinzhengjie ~]#

[root@yinzhengjie ~]# lsof -i 6                                #仅获取ipv6的流量

[root@yinzhengjie ~]# lsof -iTCP
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
sshd root 3u IPv4 0t0 TCP *:ssh (LISTEN)
sshd root 4u IPv6 0t0 TCP *:ssh (LISTEN)
httpd root 4u IPv6 0t0 TCP *:http (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
mysqld mysql 13u IPv6 0t0 TCP *:mysql (LISTEN)
mysqld mysql 86u IPv6 0t0 TCP node105.yinzhengjie.org.cn:mysql->10.19.104.189: (ESTABLISHED)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
master root 13u IPv4 0t0 TCP localhost:smtp (LISTEN)
master root 14u IPv6 0t0 TCP localhost:smtp (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
sshd root 3u IPv4 0t0 TCP node105.yinzhengjie.org.cn:ssh->10.19.104.189: (ESTABLISHED)
cmf-agent root 8u IPv4 0t0 TCP localhost:->localhost: (ESTABLISHED)
cmf-agent root 12u IPv4 0t0 TCP node105.yinzhengjie.org.cn:cslistener (LISTEN)
cmf-agent root 13u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
cmf-agent root 15u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
cmf-agent root 16u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
python root 4u IPv4 0t0 TCP localhost: (LISTEN)
python root 6u IPv4 0t0 TCP localhost:->localhost: (ESTABLISHED)
python2. root 7u IPv4 0t0 TCP *: (LISTEN)
python2. root 8u IPv4 0t0 TCP *:vop (LISTEN)
python2. root 10u IPv6 0t0 TCP *: (LISTEN)
python2. root 11u IPv6 0t0 TCP *: (LISTEN)
python2. root 14u IPv4 0t0 TCP localhost: (LISTEN)
java hdfs 173u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java hdfs 179u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 180u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node103.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 189u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node104.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 190u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 191u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 192u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node102.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 193u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node104.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 200u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 206u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system (LISTEN)
java hdfs 216u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc (LISTEN)
java hdfs 226u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 227u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 230u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node102.yinzhengjie.org.cn: (ESTABLISHED)
java httpfs 44u IPv4 0t0 TCP *:scotty-ft (LISTEN)
java httpfs 46u IPv4 0t0 TCP localhost:sua (LISTEN)
java hdfs 164u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:oa-system (ESTABLISHED)
java hdfs 169u IPv4 0t0 TCP node105.yinzhengjie.org.cn:qbdb (LISTEN)
java hdfs 192u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn:eforward (ESTABLISHED)
java hdfs 193u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 142u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client (LISTEN)
java mapred 153u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 155u IPv4 0t0 TCP *: (LISTEN)
java mapred 165u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 169u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 170u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node104.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 171u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node103.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 172u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node102.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 161u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 177u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 188u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 198u IPv4 0t0 TCP node105.yinzhengjie.org.cn:pro-ed (LISTEN)
java yarn 208u IPv4 0t0 TCP node105.yinzhengjie.org.cn:radan-http (LISTEN)
java yarn 212u IPv4 0t0 TCP node105.yinzhengjie.org.cn:mindprint (LISTEN)
java yarn 222u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node102.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 223u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 224u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node104.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 180u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 191u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 195u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 208u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
java mapred 211u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java spark 342u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
java spark 347u IPv4 0t0 TCP *: (LISTEN)
java spark 292u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
java spark 297u IPv4 0t0 TCP *: (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
sshd root 3u IPv4 0t0 TCP node105.yinzhengjie.org.cn:ssh->10.19.104.189: (ESTABLISHED)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -iTCP |wc -l [root@yinzhengjie ~]#

[root@yinzhengjie ~]# lsof -iTCP                                #仅显示TCP信息

[root@yinzhengjie ~]# lsof -iUDP
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
chronyd chrony 1u IPv4 0t0 UDP localhost:
chronyd chrony 2u IPv6 0t0 UDP localhost:
python2. root 12u IPv4 0t0 UDP *:
python2. root 13u IPv6 0t0 UDP *:
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -iUDP | wc -l [root@yinzhengjie ~]#

[root@yinzhengjie ~]# lsof -iUDP [root@yinzhengjie ~]# lsof -iUDP            #仅显示UDP信息

8>.显示与指定端口相关的网络信息

[root@yinzhengjie ~]# lsof -i:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java hdfs 173u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
[root@yinzhengjie ~]#  

9>.显示指定到指定主机的连接

[root@yinzhengjie ~]# lsof -i@node101.yinzhengjie.org.cn
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
cmf-agent root 13u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
cmf-agent root 15u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
cmf-agent root 16u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
java hdfs 179u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 193u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 153u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 161u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 225u IPv4 0t0 TCP node105.yinzhengjie.org.cn:radan-http->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 175u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 211u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
[root@yinzhengjie ~]#

10>.找出正在等候链接的端口

[root@yinzhengjie ~]# lsof -i -sTCP:LISTEN
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
sshd root 3u IPv4 0t0 TCP *:ssh (LISTEN)
sshd root 4u IPv6 0t0 TCP *:ssh (LISTEN)
httpd root 4u IPv6 0t0 TCP *:http (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
mysqld mysql 13u IPv6 0t0 TCP *:mysql (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
master root 13u IPv4 0t0 TCP localhost:smtp (LISTEN)
master root 14u IPv6 0t0 TCP localhost:smtp (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
cmf-agent root 12u IPv4 0t0 TCP node105.yinzhengjie.org.cn:cslistener (LISTEN)
python root 4u IPv4 0t0 TCP localhost: (LISTEN)
python2. root 7u IPv4 0t0 TCP *: (LISTEN)
python2. root 8u IPv4 0t0 TCP *:vop (LISTEN)
python2. root 10u IPv6 0t0 TCP *: (LISTEN)
python2. root 11u IPv6 0t0 TCP *: (LISTEN)
python2. root 14u IPv4 0t0 TCP localhost: (LISTEN)
java hdfs 173u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java hdfs 206u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system (LISTEN)
java hdfs 216u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc (LISTEN)
java httpfs 44u IPv4 0t0 TCP *:scotty-ft (LISTEN)
java httpfs 46u IPv4 0t0 TCP localhost:sua (LISTEN)
java hdfs 169u IPv4 0t0 TCP node105.yinzhengjie.org.cn:qbdb (LISTEN)
java mapred 142u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client (LISTEN)
java mapred 155u IPv4 0t0 TCP *: (LISTEN)
java mapred 169u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 177u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 188u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 198u IPv4 0t0 TCP node105.yinzhengjie.org.cn:pro-ed (LISTEN)
java yarn 208u IPv4 0t0 TCP node105.yinzhengjie.org.cn:radan-http (LISTEN)
java yarn 212u IPv4 0t0 TCP node105.yinzhengjie.org.cn:mindprint (LISTEN)
java mapred 180u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 191u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 195u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java spark 347u IPv4 0t0 TCP *: (LISTEN)
java spark 297u IPv4 0t0 TCP *: (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -i -sTCP:LISTEN | wc -l [root@yinzhengjie ~]#

[root@yinzhengjie ~]# lsof -i -sTCP:LISTEN

[root@yinzhengjie ~]# lsof -i | grep -i LISTEN
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
sshd root 3u IPv4 0t0 TCP *:ssh (LISTEN)
sshd root 4u IPv6 0t0 TCP *:ssh (LISTEN)
httpd root 4u IPv6 0t0 TCP *:http (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_ag zabbix 4u IPv4 0t0 TCP *:zabbix-agent (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
mysqld mysql 13u IPv6 0t0 TCP *:mysql (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
master root 13u IPv4 0t0 TCP localhost:smtp (LISTEN)
master root 14u IPv6 0t0 TCP localhost:smtp (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
zabbix_se zabbix 5u IPv4 0t0 TCP *:zabbix-trapper (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
cmf-agent root 12u IPv4 0t0 TCP node105.yinzhengjie.org.cn:cslistener (LISTEN)
python root 4u IPv4 0t0 TCP localhost: (LISTEN)
python2. root 7u IPv4 0t0 TCP *: (LISTEN)
python2. root 8u IPv4 0t0 TCP *:vop (LISTEN)
python2. root 10u IPv6 0t0 TCP *: (LISTEN)
python2. root 11u IPv6 0t0 TCP *: (LISTEN)
python2. root 14u IPv4 0t0 TCP localhost: (LISTEN)
java hdfs 173u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java hdfs 206u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system (LISTEN)
java hdfs 216u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc (LISTEN)
java httpfs 44u IPv4 0t0 TCP *:scotty-ft (LISTEN)
java httpfs 46u IPv4 0t0 TCP localhost:sua (LISTEN)
java hdfs 169u IPv4 0t0 TCP node105.yinzhengjie.org.cn:qbdb (LISTEN)
java mapred 142u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client (LISTEN)
java mapred 155u IPv4 0t0 TCP *: (LISTEN)
java mapred 169u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 177u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 188u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java yarn 198u IPv4 0t0 TCP node105.yinzhengjie.org.cn:pro-ed (LISTEN)
java yarn 208u IPv4 0t0 TCP node105.yinzhengjie.org.cn:radan-http (LISTEN)
java yarn 212u IPv4 0t0 TCP node105.yinzhengjie.org.cn:mindprint (LISTEN)
java mapred 180u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 191u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java mapred 195u IPv4 0t0 TCP node105.yinzhengjie.org.cn: (LISTEN)
java spark 347u IPv4 0t0 TCP *: (LISTEN)
java spark 297u IPv4 0t0 TCP *: (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
httpd apache 4u IPv6 0t0 TCP *:http (LISTEN)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -i | grep -i LISTEN | wc -l [root@yinzhengjie ~]#

[root@yinzhengjie ~]# lsof -i | grep -i LISTEN

11>.找出已经建立链接的端口

[root@yinzhengjie ~]# lsof -i -sTCP:ESTABLISHED
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld mysql 86u IPv6 0t0 TCP node105.yinzhengjie.org.cn:mysql->10.19.104.189: (ESTABLISHED)
sshd root 3u IPv4 0t0 TCP node105.yinzhengjie.org.cn:ssh->10.19.104.189: (ESTABLISHED)
cmf-agent root 8u IPv4 0t0 TCP localhost:->localhost: (ESTABLISHED)
cmf-agent root 13u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
cmf-agent root 15u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
cmf-agent root 16u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
python root 6u IPv4 0t0 TCP localhost:->localhost: (ESTABLISHED)
java hdfs 179u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 180u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node103.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 189u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node104.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 190u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 191u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 192u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node102.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 193u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 196u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node104.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 226u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 227u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 230u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node102.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 164u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:oa-system (ESTABLISHED)
java hdfs 192u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn:eforward (ESTABLISHED)
java hdfs 193u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 153u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 170u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node104.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 171u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node103.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 172u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node102.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 161u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 222u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node102.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 223u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 224u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node104.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 208u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
java mapred 211u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java spark 342u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
java spark 292u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
sshd root 3u IPv4 0t0 TCP node105.yinzhengjie.org.cn:ssh->10.19.104.189: (ESTABLISHED)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -i -sTCP:ESTABLISHED | wc -l [root@yinzhengjie ~]#

[root@yinzhengjie ~]# lsof -i -sTCP:ESTABLISHED

[root@yinzhengjie ~]# lsof -i -sTCP:ESTABLISHED | grep ESTABLISHED
mysqld mysql 86u IPv6 0t0 TCP node105.yinzhengjie.org.cn:mysql->10.19.104.189: (ESTABLISHED)
sshd root 3u IPv4 0t0 TCP node105.yinzhengjie.org.cn:ssh->10.19.104.189: (ESTABLISHED)
cmf-agent root 8u IPv4 0t0 TCP localhost:->localhost: (ESTABLISHED)
cmf-agent root 13u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
cmf-agent root 15u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
cmf-agent root 16u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn:palace- (ESTABLISHED)
python root 6u IPv4 0t0 TCP localhost:->localhost: (ESTABLISHED)
java hdfs 179u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 180u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node103.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 189u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node104.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 190u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 191u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-svcdisc->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 192u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 193u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node102.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 194u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node104.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 227u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node105.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 230u IPv4 0t0 TCP node105.yinzhengjie.org.cn:oa-system->node102.yinzhengjie.org.cn: (ESTABLISHED)
java hdfs 164u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:oa-system (ESTABLISHED)
java hdfs 192u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn:eforward (ESTABLISHED)
java hdfs 193u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 153u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 170u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node104.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 171u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node103.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 172u IPv4 0t0 TCP node105.yinzhengjie.org.cn:intu-ec-client->node102.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 161u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 222u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node102.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 223u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node103.yinzhengjie.org.cn: (ESTABLISHED)
java yarn 224u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node104.yinzhengjie.org.cn: (ESTABLISHED)
java mapred 211u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node101.yinzhengjie.org.cn: (ESTABLISHED)
java spark 342u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
java spark 292u IPv4 0t0 TCP node105.yinzhengjie.org.cn:->node105.yinzhengjie.org.cn:intu-ec-svcdisc (ESTABLISHED)
sshd root 3u IPv4 0t0 TCP node105.yinzhengjie.org.cn:ssh->10.19.104.189: (ESTABLISHED)
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -i -sTCP:ESTABLISHED | grep ESTABLISHED | wc -l [root@yinzhengjie ~]#

[root@yinzhengjie ~]# lsof -i -sTCP:ESTABLISHED | grep ESTABLISHED

12>.查看某个进程打开的文件句柄

[root@yinzhengjie ~]# jps
ResourceManager
JobTracker
NameNode
Bootstrap
DFSZKFailoverController
Jps
HistoryServer
HistoryServer
JobHistoryServer
[root@yinzhengjie ~]#
[root@yinzhengjie ~]# lsof -p | wc -l [root@yinzhengjie ~]#

   我在实际工作中能用到的参数也就是上面这些了,其他的都不咋常用。lsof的功能可不止这些哟~不知道大家观察到我在一开始贴出来的lsof的帮助信息没有?那里面记录着很多参数,感兴趣的小伙伴可以仔细研究一下~

Linux下查看某个进程打开的文件数-losf工具常用参数介绍的更多相关文章

  1. linux中,查看某个进程打开的文件数?

    需求描述: 今天在处理一个问题的时候,涉及到查看某个进程打开的文件数,在此记录下. 操作过程: 1.通过lsof命令查看某个特定的进程打开的文件数 [root@hadoop3 ~]# lsof -p ...

  2. linux下进程的最大线程数、进程最大数、进程打开的文件数

    linux下进程的最大线程数.进程最大数.进程打开的文件数   ===========最大线程数============== linux 系统中单个进程的最大线程数有其最大的限制 PTHREAD_TH ...

  3. ARTS-S linux查看进程打开的文件数

    当怀疑进程打开文件没有关闭时,可以反复执行以下命令,查看进程打开的文件数是否会不断增加. ls -l /proc/18707/fd | wc -l 其中18707是进程id

  4. inux下进程的最大线程数、进程最大数、进程打开的文件数

    inux下进程的最大线程数.进程最大数.进程打开的文件数 2008-12-07 23:48 =========================    如下转载自这里. linux 系统中单个进程的最大 ...

  5. linux下查看当前进程以及杀死进程

    ###linux下查看当前进程以及杀死进程 查看进程 ps命令查找与进程相关的PID号: ps a :显示现行终端机下的所有程序,包括其他用户的程序. ps -A :显示所有程序. ps c :列出程 ...

  6. (转)linux下进程的进程最大数、最大线程数、进程打开的文件数和ulimit命令修改硬件资源限制

    ulimit命令查看和更改系统限制 ulimit命令详解 ulimit用于shell启动进程所占用的资源,可以用来设置系统的限制 语法格式 ulimit [-acdfHlmnpsStvw] [size ...

  7. [转] linux 下查看一个进程运行路径的方法

    http://blog.csdn.net/brioxu/article/details/5104736 在linux下查看进程大家都会想到用 ps -ef|grep XXX ps -aux | hea ...

  8. linux 下查看java进程

    linux下查看出问题的java进程,便于发现程序问题.命令如下: 找到存在问题的java进程号,ps -ef|grep java ,如进程30021 卡住,需要查看该进程信息,那么敲入命令: jst ...

  9. linux 下查看一个进程执行路径

    在linux下查看进程大家都会想到用 ps -ef|grep XXX 但是看到的不是全路径.怎么看全路径呢? 每一个进程启动之后在 /proc以下有一个于pid相应的路径 比如:ps -ef|grep ...

随机推荐

  1. 【C/C++】龙格库塔+亚当姆斯求解数值微分初值问题

    /* 解数值微分初值问题: 龙格-库塔法求前k个初值 + 亚当姆斯法 */ #include<bits/stdc++.h> using namespace std; double f(do ...

  2. 解决Docker容器中不能用vim编辑文件

    更新来源: apt-get update 安装vim apt-get install -y vim 参考链接:https://blog.csdn.net/wangxinxinsj/article/de ...

  3. [NOIP]2017列队——旋转treap/非旋转treap

    Sylvia 是一个热爱学习的女孩子.  前段时间,Sylvia 参加了学校的军训.众所周知,军训的时候需要站方阵. Sylvia所在的方阵中有n × m名学生,方阵的行数为 n,列数为m.  为了便 ...

  4. 基准对象object中的基础类型----元组 (五)

    object有如下子类: CLASSES object basestring str unicode buffer bytearray classmethod complex dict enumera ...

  5. 洛谷P1373小a和uim大逃离题解

    题目 这个题好坑啊,首先是他会卡空间,然后我们就只能把一种比较好理解的状态给舍弃,因为空间开不下,然而采用一种难理解的状态就是\(dp[i][j][l][0/1]\)表示\(i\),\(j\)位置,两 ...

  6. ☆ [HDU2157] How many ways?? 「矩阵乘法求路径方案数」

    传送门:>Here< 题意:给出一张有向图,问从点A到点B恰好经过k个点(包括终点)的路径方案数 解题思路 一道矩阵乘法的好题!妙哉~ 话说把矩阵乘法放在图上好神奇,那么跟矩阵唯一有关的就 ...

  7. 【BZOJ1580】【USACO2009Hol】杀手游戏 计算几何

    题目描述 一个平面上有很多个点在运动.给你每个点的初始坐标和每个点的速度,求出最多有多少个点到\(0\)号店的距离同时不超过\(r\). \(n\leq 50000\) 题解 我们先把\(0\)号点平 ...

  8. Leetcode 202.快乐数 By Python

    编写一个算法来判断一个数是不是"快乐数". 一个"快乐数"定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 ...

  9. 【BZOJ5417】[NOI2018]你的名字(线段树,后缀自动机)

    [BZOJ5417][NOI2018]你的名字(线段树,后缀自动机) 题面 BZOJ 洛谷 题解 首先考虑\(l=1,r=|S|\)的做法,对于每次询问的\(T\)串,暴力在\(S\)串的\(SAM\ ...

  10. 【arc073f】Many Moves(动态规划,线段树)

    [arc073f]Many Moves(动态规划,线段树) 题面 atcoder 洛谷 题解 设\(f[i][j]\)表示第一个棋子在\(i\),第二个棋子在\(j\)的最小移动代价. 发现在一次移动 ...