Getting Kernel Information¶
procfs¶
Linux offers various interfaces to expose internal kernel information. One of them is procfs (Process Filesystem).
Linux shows information through files under /proc. Every file under the directory is an interface for accessing to particular information.
The following command is an example to get CPU information through procfs.:
$ cat /proc/cpuinfo
If you wish to get memory information, please type following command:
$ cat /proc/meminfo
For accessing information for a specific process, we should look into a directory /proc/PID.
For instance, we can see the generic status of a process whose PID is 1.:
$ sudo cat /proc/1/status
We can see the virtual address mapping of a process whose PID is 1 by the following command.:
$ sudo cat /proc/1/maps
By the way, we can do the same thing through the standard read operation:
$ python3
>>> fp = open('/proc/cpuinfo', 'r')
>>> content = fp.read()
>>> fp.close()
>>> print(content)
sysfs¶
The concept of sysfs is similar to procfs. Mainly sysfs is used for showing information about kernel sub-systems, hardware and device drivers.
It depends on situations, but procfs may offer much more interesting information.