Linux中查看当前的socket状态:
IPV4:
[root@centos ~]# cat /proc/net/sockstat
sockets: used 96
TCP: inuse 3 orphan 0 tw 0 alloc 3 mem 1
UDP: inuse 2 mem 0
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0
注:
sockets: used:已使用的所有协议套接字总量
TCP: inuse:正在使用(正在侦听)的TCP套接字数量。其值≤ netstat –lnt | grep ^tcp | wc –l
orphan:无主(不属于任何进程)的TCP连接数(无用、待销毁的TCP socket数)
tw:等待关闭的TCP连接数。其值等于netstat –ant | grep TIME_WAIT | wc –l
alloc(allocated):已分配(已建立、已申请到sk_buff)的TCP套接字数量。其值等于netstat –ant | grep ^tcp | wc –l
TCP:mem:套接字缓冲区使用量
UDP:inuse:正在使用的UDP套接字数量; mem:套接字缓冲区使用量
RAW:RAW socket个数,可以收发包含IP层的报文
FRAG:使用的IP段数量
IPv6:
[root@centos ~]# cat /proc/net/sockstat6
TCP6: inuse 0
UDP6: inuse 1
UDPLITE6: inuse 0
RAW6: inuse 0
FRAG6: inuse 0 memory 0
(1)Linux系统下,所有进程允许打开的最大fd数量。查询语句:
[root@centos ~]# cat /proc/sys/fs/file-max
182682
(2)Linux系统下,所有进程已经打开的fd数量及允许的最大数量。查询语句:
[root@centos ~]# cat /proc/sys/fs/file-nr
768 0 182682
(3)单个进程允许打开的最大fd数量.查询语句:
[root@centos ~]# ulimit -n
65535
(4)单个进程(例如进程id为875)已经打开的fd.查询语句:
[root@centos ~]# ls -l /proc/875/fd/
total 0
l-wx------ 1 root root 64 Aug 24 16:11 0 -> /dev/null
l-wx------ 1 root root 64 Aug 24 16:11 1 -> /dev/null
lr-x------ 1 root root 64 Aug 24 16:11 10 -> anon_inode:inotify
lrwx------ 1 root root 64 Aug 24 16:11 11 -> anon_inode:[fanotify]
lrwx------ 1 root root 64 Aug 24 16:11 12 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 Aug 24 16:11 13 -> /usr/local/aegis/globalcfg/aegisdb/dircache.db
lrwx------ 1 root root 64 Aug 24 16:11 14 -> /usr/local/aegis/globalcfg/aegisdb/dircache.db
lrwx------ 1 root root 64 Aug 24 16:11 15 -> socket:[14218]
lrwx------ 1 root root 64 Aug 24 16:11 16 -> /usr/local/aegis/globalcfg/cache/aegis_file_cache.db
lrwx------ 1 root root 64 Aug 24 16:11 17 -> /usr/local/aegis/globalcfg/aegisdb/wt.db
lrwx------ 1 root root 64 Aug 24 16:11 18 -> socket:[15834]
lrwx------ 1 root root 64 Aug 24 16:11 19 -> /usr/local/aegis/globalcfg/aegisdb/webshell.db
l-wx------ 1 root root 64 Aug 24 16:11 2 -> /dev/null
lrwx------ 1 root root 64 Aug 24 16:11 20 -> /usr/local/aegis/globalcfg/aegisdb/scanpath.db
lrwx------ 1 root root 64 Aug 24 16:11 21 -> socket:[14311]
lrwx------ 1 root root 64 Aug 24 16:11 23 -> socket:[16421]
lrwx------ 1 root root 64 Aug 24 16:11 3 -> /usr/local/aegis/aegis_client/aegis_10_97/singleApp_aegisInner
lrwx------ 1 root root 64 Aug 24 16:11 4 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 Aug 24 16:11 5 -> socket:[14206]
lrwx------ 1 root root 64 Aug 24 16:11 6 -> socket:[14207]
lrwx------ 1 root root 64 Aug 24 16:11 7 -> socket:[14208]
lrwx------ 1 root root 64 Aug 24 16:11 8 -> socket:[14209]
lrwx------ 1 root root 64 Aug 24 16:11 9 -> socket:[14210]
|