这很令人费解。有谁知道hostname命令从哪里存储和读取主机名?
我认为它是 /etc/hostname 但在我使用的这个 Linux 系统上没有这样的文件。我尝试使用 strace 查找它所在的位置,但没有读取调用返回此信息:
$ strace hostname 2>&1 | grep read
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340^\0\0\0\0\0\0"..., 832) = 832
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\30\2\0\0\0\0\0"..., 832) = 832
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\16\0\0\0\0\0\0"..., 832) = 832
read(3, "nodev\tsysfs\nnodev\trootfs\nnodev\tr"..., 1024) = 248
read(3, "", 1024) = 0
Run Code Online (Sandbox Code Playgroud)
然后我注意到它确实返回了此信息的 uname 系统调用:
uname({sys="Linux", node="server-name", ...}) = 0
Run Code Online (Sandbox Code Playgroud)
/etc/ 中的递归 grep 不返回任何内容:
grep "server-name" -r /etc
Run Code Online (Sandbox Code Playgroud)
uname 在哪里存储这些信息?只是在记忆中?