1 分析
1.1 Linux的who命令可以做什么
通过who命令可以查看当前已登录的用户
1.2 linux的who命令是如何实现的
1.2.1 通过man获得信息
在命令行中输入
man who
在帮助文档中没有写出who是如何实现的,但是在最后
SEE ALSO
The full documentation for who is maintained as a Texinfo manual. If
the info and who programs are properly installed at your site, the com-
mandinfo coreutils 'who invocation' should give you access to the complete manual.
发现可以再 info中查看更详细的介绍
1.2.2 通过info获得信息
在命令行输入
info coreutils 'who invocation'
在显示的内容中有这么一段话
If given one non-option argument,
who' uses that instead of a
/var/run/utmp’ or
default system-maintained file (often
/var/run/utmp') as the name of the file containing the record of users
/var/log/wtmp’ is commonly given as an argument to `who’
logged on.
to look at who has previously logged on.
可以知道默认情况who是读取/var/run/utmp的内容来显示的,如果直接打开该文件,会发现是一段乱码,上网查阅该文件
1.2.3 通过谷歌获取信息
在man.org7中可以看到对该文件的描述
The utmp file allows one to discover information about who is
currently using the system. There may be more users currently using
the system, because not all programs use utmp logging.
The file is a sequence of utmp structures, declared as follows in
/* Compatibility names for the strings of the canonical file names. */
#define UTMP_FILE _PATH_UTMP
#define UTMP_FILENAME _PATH_UTMP
但是,在其中包含了一个
/* Get system dependent values and data structures. */
#include <bits/utmp.h>
于是打开在该目录下的utmp.h