赞
踩
lsof用于查看文件的打开状况,用于调试程序,查看系统情况
输出的各项信息
lsof输出各列信息的意义如下:
COMMAND:进程的名称
PID:进程标识符
USER:进程所有者
FD:文件描述符,应用程序通过文件描述符识别该文件。每个进程都有自己的文件描述符表,因此FD可能会重名
TYPE:文件类型
DEVICE:指定磁盘的名称
SIZE:文件的大小
NODE:索引节点(文件在磁盘上的标识)
NAME:打开文件的确切名称
-p 选项,列出pid所打开的文件
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 32463 root cwd DIR 8,8 4096 2121777 /www/data/tomcat/bin
-u 选项, 列出某个用户打开的文件
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 2104 wang cwd unknown /proc/2104/cwd (readlink: Permission denied)
sshd 2104 wang rtd unknown /proc/2104/root (readlink: Permission denied)
-i 的使用,这个比较有用
整体格式如下:
lsof -i[46] [protocol][@hostname|hostaddr][:service|port]
46 –> IPv4 or IPv6
protocol –> TCP or UDP
hostname –> Internet host name
hostaddr –> IPv4地址
service –> /etc/service中的 service name (可以不止一个)
port –> 端口号 (可以不止一个)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
redis-ser 6418 root 3231u IPv4 871410697 0t0 TCP 192.168.20.30:6380->192.168.20.31:30085 (ESTABLISHED)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 1818 root 387u IPv4 884293373 0t0 TCP wang_zk1:wang.com:30471 (ESTABLISHED)
java 1818 root 388u IPv4 884293374 0t0 TCP wang_zk1:wang.com:30469 (ESTABLISHED)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 1818 root 387u IPv4 884293373 0t0 TCP wang_zk1:wang.com:30471 (ESTABLISHED)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 8743 root 49u IPv4 771370268 0t0 TCP *:1883 (LISTEN)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 8743 root 49u IPv4 771370268 0t0 TCP *:1883 (LISTEN)
main 16184 root 13u IPv4 225274829 0t0 TCP localhost:w1884 (LISTEN)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 5604 www 16u IPv4 82923 0t0 TCP *:http (LISTEN)
nginx 5605 www 16u IPv4 82923 0t0 TCP *:http (LISTEN)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
memcached 7777 nobody 27u IPv4 140461247 0t0 UDP wang_zk1:22622
memcached 12659 nobody 41u IPv4 771440826 0t0 TCP wang_zk1:memcache->wang_zk1:16054 (ESTABLISHED)
memcached 12659 nobody 42u IPv4 771248651 0t0 TCP wang_zk1:memcache->wang_zk1:46769 (ESTABLISHED)
memcached 12659 nobody 43u IPv4 771379102 0t0 TCP wang_zk1:memcache->wang_zk1:10402 (ESTABLISHED)
memcached 12659 nobody 44u IPv4 3907515697 0t0 TCP wang_zk1:memcache->wang_zk1:56351 (ESTABLISHED)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 5604 www 16u IPv4 82923 0t0 TCP *:http (LISTEN)
nginx 5605 www 16u IPv4 82923 0t0 TCP *:http (LISTEN)
nginx 5606 www 16u IPv4 82923 0t0 TCP *:http (LISTEN)
redis-ser 6418 root 3231u IPv4 871410697 0t0 TCP 192.168.20.30:6380->192.168.20.31:30085 (ESTABLISHED)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 32463 root 51u IPv4 3511973379 0t0 TCP 192.168.20.30:25285->192.168.7.141:http (CLOSE_WAIT)
java 32463 root 53u IPv4 3511079896 0t0 TCP 192.168.20.30:35451->192.168.7.141:http (CLOSE_WAIT)
-c 选项
-s 选项,选择TCP,UDP的连接状况
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
zabbix_ag 632 monitor 6u IPv4 156403268 0t0 TCP *:monitor-agent (LISTEN)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 13413 root 94u IPv4 844561512 0t0 TCP 192.168.20.30:59289->192.168.20.30:8092 (ESTABLISHED)
TCP状态:CLOSED,IDLE,BOUND,LISTEN,ESTABLISHED,SYN_SENT,SYN_RCDV,CLOSE_WAIT,FIN_WAIT1,CLOSING,LAST_ACK,FIN_WAIT_2,TIME_WAIT
UDB状态: Unbound , Idle
-T 选项,显示网络端口的情况
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 3603 root 49u IPv4 884372618 0t0 TCP *:1883 (QR=0 QS=0)
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 5604 www 16u IPv4 82923 0t0 TCP *:http (LISTEN)
查看某个文件的打开情况
[sudo] password for wang:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 8743 root cwd DIR 8,8 4096 3014674 /www/data/tomcat
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 1818 root mem REG 8,7 32768 394070 /tmp/hsperfdata_root/1818
+d 选项
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 3603 root cwd DIR 8,8 4096 3014674 /www/data/tomcat
-d 选项
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ntpd 553 ntp 16u IPv4 1954763371 0t0 UDP *:ntp
hald 1237 haldaemon 16r REG 0,3 0 4026531979 /proc/mdstat
+D 选项
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python 2806 root 6r REG 8,8 159675 3024730 /www/data/tomcat/logs/bigdata.log
java 8743 root cwd DIR 8,8 4096 3014674 /www/data/tomcat
java 8743 root mem REG 8,8 124266 3015949 /www/data/tomcat/lib/jasper-e
-a 选项 多个条件AND
-U 显示所有Unix domain sockets相关情况
sudo 1808 root 4u unix 0xffff88032a858d80 0t0 2191544754 socket
java 2545 root 48u unix 0xffff8802f487cec0 0t0 3146212706 socket
sudo 2697 root 4u unix 0xffff88010cadf7c0 0t0 841102828 socket
java 2698 root 26u unix 0xffff88032a859740 0t0 841102853 socket
java 2698 root 36u unix 0xffff88042b642f40 0t0 841102861 socket
nginx 3096 www 17u unix 0xffff880429f07400 0t0 4166624772 socket
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 2545 root 48u unix 0xffff8802f487cec0 0t0 3146212706 socket
java 2698 root 26u unix 0xffff88032a859740 0t0 841102853 socket
java 2698 root 36u unix 0xffff88042b642f40 0t0 841102861 socket
java 3241 root 53u unix 0xffff8802fe1cbac0 0t0 3920291480 socket
java 3241 root 172u unix 0xffff8802fe1ca740 0t0 3920299347 socket
java 3865 root 26u unix 0xffff88019c8c8c00 0t0 841135846 socket
java 3865 root 37u unix 0xffff88022c3f9500 0t0 841136956 socket
-l 选项,展示USER ID, 不展示具体用户名,辅助选项
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 5604 514 16u IPv4 82923 0t0 TCP *:http (LISTEN)
nginx 5605 514 16u IPv4 82923 0t0 TCP *:http (LISTEN)
-n 选项,展示主机ip而不是主机名,辅助选项
redis-ser 6418 root 3231u IPv4 871410697 0t0 TCP 192.168.20.30:6380->192.168.20.31:30085 (ESTABLISHED)
-o 选项,把SIZE/OFF 换成OFFSET,辅助选项
COMMAND PID USER FD TYPE DEVICE OFFSET NODE NAME
java 3603 root cwd DIR 8,8 3014674 /www/data/tomcat
-P 选项,实现端口数字,而不是端口含义,辅助选项
-r 选项,每隔多少秒显示一次,辅助选项
+r 选项,每隔多少秒显示一次,辅助选项
-s 选项,SIZE/OFF 只展示SIZE 辅助选项
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。