I am trying to get the diskstats data by same way that the file does. Is there any way to reach that values without reading that file? How the values are placed there? Is there any ".c" file that processes the data to place on diskstats? And for proc/stat and meminfo? (diskstats is my main concern)

1 Answer 1


The /proc files — or, rather, pseudo-files — are a data interface between user processes and the kernel.  When a (user-)process opens a /proc file and reads from it, the kernel provides the data.  So, yes, there is a .c routine that generates the diskstats data — but it’s part of the kernel.

Some of the data accessible through the proc pseudo-filesystem is accessible from other sources and/or through other means.  As a trivial example, a process generally has direct access to a lot of the information that can be gleaned from its own /proc/pid directory.  However, most of the /proc information comes from kernel data structures that are not generally accessible to user processes.  It may be possible for a privileged user-level process to extract this information from the kernel using /dev/kmem (see mem(4) and kmem(7D)) — on those systems that support it — but this would be very difficult, probably non-portable, and generally not recommended.  For all practical purposes, /proc is the only way to get that data.

You must log in to answer this question.

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