计算打开文件数的正确方法是什么

计算打开文件数的正确方法是什么

验证打开文件的真正方法是什么

我们所做的是

lsof  | sort | uniq >/tmp/file

因此/tmp/file包括所有打开的文件

并且可以通过以下方式识别打开文件的数量

wc -l /tmp/file
3259806 /tmp/file

直到现在很酷

但是当我们查看该文件时我们看到

more /tmp/file

abrt-dbus 189428                  root    1u     unix 0xffff883fcd70c380       0t0      61987 socket
abrt-dbus 189428                  root    2u     unix 0xffff883fcd70c380       0t0      61987 socket
abrt-dbus 189428                  root    3u  a_inode                0,9         0       7411 [eventfd]
abrt-dbus 189428                  root    4u     unix 0xffff883da772cb00       0t0 3903424237 socket
abrt-dbus 189428                  root    5u  a_inode                0,9         0       7411 [eventfd]
abrt-dbus 189428                  root  mem       REG              253,0    110808  201609749 /usr/lib64/libresolv-2.17.so
abrt-dbus 189428                  root  mem       REG              253,0   1141560  201609729 /usr/lib64/libm-2.17.so
abrt-dbus 189428                  root  mem       REG              253,0    118672  202713390 /usr/lib64/libpolkit-gobject-1.so.0.0.0
abrt-dbus 189428                  root  mem       REG              253,0   1257792  203905333 /usr/lib64/libnss3.so
abrt-dbus 189428                  root  mem       REG              253,0   1287904  201610325 /usr/lib64/libglib-2.0.so.0.4200.2
abrt-dbus 189428                  root  mem       REG              253,0    142304  201609747 /usr/lib64/libpthread-2.17.so
abrt-dbus 189428                  root  mem       REG              253,0    147096  201609950 /usr/lib64/libselinux.so.1

那么以下几行是否也需要被视为打开文件?或者不是?

abrt-dbus 189428                  root    1u     unix 0xffff883fcd70c380       0t0      61987 socket
abrt-dbus 189428                  root    2u     unix 0xffff883fcd70c380       0t0      61987 socket
abrt-dbus 189428                  root    3u  a_inode                0,9         0       7411 [eventfd]
abrt-dbus 189428                  root    4u     unix 0xffff883da772cb00       0t0 3903424237 socket
abrt-dbus 189428                  root    5u  a_inode                0,9         0       7411 

或者

我们只需要计算以以下文件结尾的行

abrt-dbus 189428                  root  mem       REG              253,0    110808  201609749 /usr/lib64/libresolv-2.17.so
abrt-dbus 189428                  root  mem       REG              253,0   1141560  201609729 /usr/lib64/libm-2.17.so
abrt-dbus 189428                  root  mem       REG              253,0    118672  202713390 /usr/lib64/libpolkit-gobject-1.so.0.0.0
abrt-dbus 189428                  root  mem       REG              253,0   1257792  203905333 /usr/lib64/libnss3.so
abrt-dbus 189428                  root  mem       REG              253,0   1287904  201610325 /usr/lib64/libglib-2.0.so.0.4200.2
abrt-dbus 189428                  root  mem       REG              253,0    142304  201609747 /usr/lib64/libpthread-2.17.so
abrt-dbus 189428                  root  mem       REG              253,0    147096  201609950 /usr/lib64/libselinux.so.1

相关内容