Sysfs

在 linux 里,sysfsprocfs 都是没有存储介质的虚拟文件系统,用于内核与用户态的交互。以下是摘自《Professional Linux Kernel Architecture》的一段话,对两者在概念上的区别进行了描述。

Sysfs is one particularly important example of another virtual filesystem that serves a similar purpose to procfs on the one hand, but is rather different on the other hand. Sysfs is, per convention, always mounted at /sys, but there is nothing that would prevent including it in other places. It was designed to export information from the kernel into userland at a highly structured level. In contrast to procfs, it was not designed for direct human use because the information is deeply and hierarchically nested. Additionally, the files do not always contain information in ASCII text form, but may well use unreadable binary strings. The filesystem is, however, very useful for tools that want to gather detailed information about the hardware present in a system and the topological connection between the devices.

简单来说就是:

  • sysfs 提供的是结构化的复杂信息,需要工具进行解析和处理;
  • procfs 提供的是直观可读的信息,用户可以直接查看。

Read More: