您无需离开终端即可找到此类问题的答案。
让我们自己看看:
# strace netstat -su &> netstat_strace
这将是一个“打开”和“读取”,因为它从某个地方获取数据(但 grep 找出它未能读取/打开的位置):
# grep -E 'open|read' netstat_strace | grep -v ENOENT
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\37\2\0\0\0\0\0"..., 832) = 832
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
open("/proc/meminfo", O_RDONLY|O_CLOEXEC) = 3
read(3, "MemTotal: 3854816 kB\nMemF"..., 1024) = 1024
open("/proc/net/snmp", O_RDONLY) = 3
read(3, "Ip: Forwarding DefaultTTL InRece"..., 4096) = 1261
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 4
read(4, "# Locale name alias data base.\n#"..., 4096) = 2570
read(4, "", 4096) = 0
read(3, "", 4096) = 0
open("/proc/net/netstat", O_RDONLY) = 3
read(3, "TcpExt: SyncookiesSent Syncookie"..., 4096) = 2158
read(3, "", 4096) = 0
通过检查strace 输出,我们可以看到它正在写入一个字符串:
write(1, "IcmpMsg:\n InType0: 11\n InT"..., 373IcmpMsg:
InType0: 11
嗯,这很有趣。让我们查看netstat 的手册页:
man netstat
如果您查看FILES:
FILES
/etc/services -- The services translation file
/proc -- Mount point for the proc filesystem, which gives access to kernel status information via the following files.
/proc/net/dev -- device information
/proc/net/raw -- raw socket information
/proc/net/tcp -- TCP socket information
/proc/net/udp -- UDP socket information
/proc/net/igmp -- IGMP multicast information
...
你可以从上面看到opened 和read 的原因。在搜索“清除”或“重置”(或阅读它)时,您会发现这些不是命令的选项。
下一步将检查man proc,它将自己描述为“进程信息伪文件系统”。
从这里,你可以知道如果你修改了 netstat 读取的文件,你可以改变 netstat 的输出(/proc/net/netstat 在我看来特别有趣)——你可以——但我' d 建议将其设为只读。