使用<a href="https://www.kernel.org/pub/linux/utils/net/iproute2/" target="_blank" rel="noopener">iproute2</a><a href="https://www.kernel.org/pub/linux/utils/net/iproute2/" target="_blank" rel="noopener"> </a> 工具包里的ss 进行查看,发现在输出的users项里会出现三个参数,第一个是进程名、第二个为pid,第三项代码什么意思呢?输出示例如下:
<br />
[root@361way ~]# ss -lp|column -t State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:ssh *:* users:(("sshd",11155,3)) LISTEN 0 128 *:cslistener *:* users:(("hhvm",6925,17)) LISTEN 0 20 *:mysql *:* users:(("mysqld",27967,10)) LISTEN 0 128 *:http *:* users:(("nginx",20211,9),("nginx",20212,9),("nginx",26283,9))
由于网上未到准确的答复,通过查看其源代码 ,在iproute2-4.0.0\misc\ss.c找到如下内容:
while (1) { ptr = *buf + buf_used; switch (type) { case USERS: len = snprintf(ptr, buf_len - buf_used, "(\"%s\",pid=%d,fd=%d),", p->process, p->pid, p->fd); break;
通过以上代码基本可以确认第三个确数为fd项---即文件描述符的使用数量。
这里先看下sshd进程的示例 ,查看下/proc的相关目录,发现一共有四个文件,排除掉一个socket的,其3个。
[root@361way ~]# ls -l /proc/11155/fd total 0 lrwx------ 1 root root 64 May 5 11:18 0 -> /dev/null lrwx------ 1 root root 64 May 5 11:18 1 -> /dev/null lrwx------ 1 root root 64 May 5 11:18 2 -> /dev/null lrwx------ 1 root root 64 May 5 11:18 3 -> socket:[5066078]
再看一下hhvm的示例:
<br />
[root@361way ~]# ls -l /proc/6925/fd total 0 lr-x------ 1 www www 64 May 5 11:18 0 -> /dev/null l-wx------ 1 www www 64 May 5 11:18 1 -> /dev/null lrwx------ 1 www www 64 May 5 11:18 10 -> [eventfd] lrwx------ 1 www www 64 May 5 11:18 11 -> [eventpoll] lrwx------ 1 www www 64 May 5 11:18 12 -> socket:[8260909] lrwx------ 1 www www 64 May 5 11:18 13 -> socket:[8260910] lrwx------ 1 www www 64 May 5 11:18 14 -> [eventfd] l-wx------ 1 www www 64 May 5 11:18 15 -> /tmp/perf-6925.map lrwx------ 1 www www 64 May 5 11:18 16 -> /home/www/.hhvm.hhbc lrwx------ 1 www www 64 May 5 11:18 17 -> socket:[8260921] lrwx------ 1 www www 64 May 5 11:18 18 -> [eventfd] l-wx------ 1 www www 64 May 5 11:18 2 -> /dev/null lrwx------ 1 www www 64 May 5 11:18 20 -> /home/www/.hhvm.hhbc lrwx------ 1 www www 64 May 5 11:18 21 -> /home/www/.hhvm.hhbc lr-x------ 1 www www 64 May 5 11:18 23 -> /etc/pki/nssdb/cert9.db lr-x------ 1 www www 64 May 5 11:18 24 -> /etc/pki/nssdb/key4.db lr-x------ 1 www www 64 May 5 11:18 3 -> /etc/hosts lrwx------ 1 www www 64 May 5 11:18 4 -> /tmp/tcPQ9pSl (deleted) l-wx------ 1 www www 64 May 5 11:18 5 -> /var/log/hhvm/error.log l-wx------ 1 www www 64 May 5 11:18 6 -> /var/log/hhvm/access.log lrwx------ 1 www www 64 May 5 11:18 7 -> [eventpoll] lrwx------ 1 www www 64 May 5 11:18 8 -> socket:[8260906] lrwx------ 1 www www 64 May 5 11:18 9 -> socket:[8260907] [root@361way ~]# ls -l /proc/6925/fd|wc -l 29 [root@361way ~]# ls -l /proc/6925/fd|grep -v socket|wc -l 19
上面排除过socket后一共19行,排除掉total行、3号文件已经deleted的,得出的结果也是17.
<strong>其他:</strong>
同样不理解的一个还有ss -m 的内存输出项,输出类似如下:
ESTAB 0 0 172.16.31.158:55266 115.114.106.17:imap2 mem:(r0,w0,f0,t0)
其中r、w、f、t的含义如下:
<br />
- r represents the read (inbound) buffer
- w represents the write (outbound) buffer
- f represents the “forward allocated memory” (memory available to the socket)
- t represents the transmit queue (stuff waiting to be sent or waiting on an ACK)
<br />