I would very much like to know the names and locations of the files from which vmstat
command information comes from in Linux OS.
Asked
Active
Viewed 61 times
-1

Leo1989
- 23
- 3
-
2then run it with strace and grep for open. – stark Aug 28 '22 at 10:26
-
1`man vmstat` has a section called `FILES` that lists which files it uses. – Robert Aug 28 '22 at 16:24
-
Not a programming specific question - try [unix.se] or [su]. – tink Aug 28 '22 at 17:36
1 Answers
0
User space tools reporting statistics likely get them from the kernel through procfs/sysfs file systems. As most of them are open sources, it is easy to read the source code. For example, a way to get the package name it comes from is to display the version:
$ vmstat --version
vmstat from procps-ng 3.3.16
From the preceding, you know that you can grab the source code from procps-ng package.
And as said in the comments by Stark, you can spy the execution of vmstat
with strace
tool and you will see which files are opened to get the information:
$ strace vmstat
[...]
openat(AT_FDCWD, "/proc/meminfo", O_RDONLY) = 3
[...]
openat(AT_FDCWD, "/proc/stat", O_RDONLY) = 4
[...]
openat(AT_FDCWD, "/proc/vmstat", O_RDONLY) = 5
[...]

Rachid K.
- 4,490
- 3
- 11
- 30