ss -p输出users项详解
使用iproute2 工具包里的ss 进行查看,发现在输出的users项里会出现三个参数,第一个是进程名、第二个为pid,第三项代码什么意思呢?输出示例如下:
1[root@361way ~]# ss -lp|column -t
2State Recv-Q Send-Q Local Address:Port Peer Address:Port
3LISTEN 0 128 *:ssh *:* users:(("sshd",11155,3))
4LISTEN 0 128 *:cslistener *:* users:(("hhvm",6925,17))
5LISTEN 0 20 *:mysql *:* users:(("mysqld",27967,10))
6LISTEN 0 128 *:http *:* users:(("nginx",20211,9),("nginx",20212,9),("nginx",26283,9))
由于网上未到准确的答复,通过查看其源代码 ,在iproute2-4.0.0\misc\ss.c找到如下内容:
1while (1) {
2 ptr = *buf + buf_used;
3 switch (type) {
4 case USERS:
5 len = snprintf(ptr, buf_len - buf_used,
6 "(\"%s\",pid=%d,fd=%d),",
7 p->process, p->pid, p->fd);
8 break;
通过以上代码基本可以确认第三个确数为fd项---即文件描述符的使用数量。
这里先看下sshd进程的示例 ,查看下/proc的相关目录,发现一共有四个文件,排除掉一个socket的,其3个。
1[root@361way ~]# ls -l /proc/11155/fd
2total 0
3lrwx------ 1 root root 64 May 5 11:18 0 -> /dev/null
4lrwx------ 1 root root 64 May 5 11:18 1 -> /dev/null
5lrwx------ 1 root root 64 May 5 11:18 2 -> /dev/null
6lrwx------ 1 root root 64 May 5 11:18 3 -> socket:[5066078]
再看一下hhvm的示例:
1[root@361way ~]# ls -l /proc/6925/fd
2total 0
3lr-x------ 1 www www 64 May 5 11:18 0 -> /dev/null
4l-wx------ 1 www www 64 May 5 11:18 1 -> /dev/null
5lrwx------ 1 www www 64 May 5 11:18 10 -> [eventfd]
6lrwx------ 1 www www 64 May 5 11:18 11 -> [eventpoll]
7lrwx------ 1 www www 64 May 5 11:18 12 -> socket:[8260909]
8lrwx------ 1 www www 64 May 5 11:18 13 -> socket:[8260910]
9lrwx------ 1 www www 64 May 5 11:18 14 -> [eventfd]
10l-wx------ 1 www www 64 May 5 11:18 15 -> /tmp/perf-6925.map
11lrwx------ 1 www www 64 May 5 11:18 16 -> /home/www/.hhvm.hhbc
12lrwx------ 1 www www 64 May 5 11:18 17 -> socket:[8260921]
13lrwx------ 1 www www 64 May 5 11:18 18 -> [eventfd]
14l-wx------ 1 www www 64 May 5 11:18 2 -> /dev/null
15lrwx------ 1 www www 64 May 5 11:18 20 -> /home/www/.hhvm.hhbc
16lrwx------ 1 www www 64 May 5 11:18 21 -> /home/www/.hhvm.hhbc
17lr-x------ 1 www www 64 May 5 11:18 23 -> /etc/pki/nssdb/cert9.db
18lr-x------ 1 www www 64 May 5 11:18 24 -> /etc/pki/nssdb/key4.db
19lr-x------ 1 www www 64 May 5 11:18 3 -> /etc/hosts
20lrwx------ 1 www www 64 May 5 11:18 4 -> /tmp/tcPQ9pSl (deleted)
21l-wx------ 1 www www 64 May 5 11:18 5 -> /var/log/hhvm/error.log
22l-wx------ 1 www www 64 May 5 11:18 6 -> /var/log/hhvm/access.log
23lrwx------ 1 www www 64 May 5 11:18 7 -> [eventpoll]
24lrwx------ 1 www www 64 May 5 11:18 8 -> socket:[8260906]
25lrwx------ 1 www www 64 May 5 11:18 9 -> socket:[8260907]
26[root@361way ~]# ls -l /proc/6925/fd|wc -l
2729
28[root@361way ~]# ls -l /proc/6925/fd|grep -v socket|wc -l
2919
上面排除过socket后一共19行,排除掉total行、3号文件已经deleted的,得出的结果也是17.
其他:
同样不理解的一个还有ss -m 的内存输出项,输出类似如下:
1ESTAB 0 0 172.16.31.158:55266 115.114.106.17:imap2 mem:(r0,w0,f0,t0)
其中r、w、f、t的含义如下:
- 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)
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/iproute2-ss-users/4355.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.