Currently I am learning Kernel Module Programming reading "https://www.tldp.org/LDP/lkmpg/2.6/lkmpg.pdf" ,and in that book there is a chapter titled as "/proc File System", I have learnt how modules are used as device drivers, but I have not been able to understand the importance of creating "/proc/file_name" by an kernel module. I know that in /proc directory kernel maintains info about processes. I need to understand the importance of creating "/proc/file_name" by an kernel module.

1 Answer 1


The beginning of chapter 5.1 says this about the /proc filesystem:

Originally designed to allow easy access to information about processes (hence the name), it is now used by every bit of the kernel which has something interesting to report, [...]

You don't have to create a file in the /proc filesystem, but if you want or need to have an easy way to report statistics or other information about the state of your module, the /proc filesystem is one way to do it. Because of the way the /proc filesystem was developed, it can be a bit disorganized. Instead of creating several things at the root of the /proc filesystem, you might want to create a sub-directory for your module at e.g. /proc/driver, to minimize the chance of conflicts with the main kernel, other third-party modules or future development.

Note that about the time that book was being written, the /sys filesystem was also introduced to be a more systematically arranged place (and so more friendly for integrating user-space tools) for any tunable settings your kernel module might have. Unfortunately, the chapter 6 that was supposed to be about it is just a TODO: Write a chapter about sysfs placeholder in that PDF.

(Historical note: before the /sys filesystem existed, the /proc filesystem was used as a place for run-time tweakable settings, usually identifiable as writeable files. Some of them might still not have been completely migrated to the /sys filesystem, or even not going to migrate at all to maintain backward compatibility. But for any modern development, it would be better to put any tunables in /sys instead of /proc.)

In modern kernels, there is also the debugfs, that can be mounted to /sys/kernel/debug, that could be a good place if your kernel module needs a way to output some debugging information. It might be a good place for outputting more detailed/sensitive debug information, as debugfs is designed for system administrator access only. It is also completely optional: in production systems the debugfs can be simply left unmounted unless there is a need for in-depth troubleshooting.

So, in a nutshell: if your module needs to provide a way to tune some settings at run-time, the /sys filesystem is a good place for them. For debugging information in modern kernels, use the debugfs. For statistics and similar stuff that can be seen by non-root users, /proc can be used.

  • you need to say that if my module wants to show some stats , just like kernel shows in "/proc/modules" which indicates that which of the modules are currently inserted , I can do that by creating file in "/proc" file system and writing the info. Mar 8, 2019 at 3:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .