7

As per my knowledge,

In Linux file system, for information communication between user space and kernel space, two kind of virtual file systems are used.

1) Proc file system http://www.tldp.org/LDP/Linux-Filesystem-Hierarchy/html/proc.html

2) sysfs file system https://en.wikipedia.org/wiki/Sysfs

In linux kernel code, i see some sub system has used proc file to perform such userspace-kernelspace communication, and some system has used sysfs files for same concern.

So i just want to know, if i am going to write new linux kernel module or driver then how to choose virtual files ? when should i use sysfs and when should i use proc file?

Please let me know if i misunderstood anything here.

Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
  • Related question: http://stackoverflow.com/questions/33873221/which-filesystem-to-use-to-expose-readings-limits-for-temperature-sensor. Also, I found [this article](http://people.ee.ethz.ch/~arkeller/linux/multi/kernel_user_space_howto-2.html). While it describes some non-process related information, placed under `/proc`, it says: `Note, despite the wide use of the procfs, it is deprecated and should only be used to export information related to a process itself.`. – Tsyvarev Dec 07 '15 at 13:12
  • 1
    Contrary to `procfs` if you intend to transfer big buffers `sysfs` is not suitable as it only accepts at most `page size` buffer size. – stdcall Dec 08 '15 at 14:57

2 Answers2

5

The only thing that is coming to my mind regarding adding/modifying entries in procfs is when you play with virtual memory subsystem itself. I'm talking about entries in /proc/sys/vm/ (so if you for some reason modify writeback, overcomit, swap, etc.). If you're writing a driver or a module that is not related to stuff already exported via procfs, you should use sysfs.

mkmk88
  • 271
  • 1
  • 4
1

After reading much i have below understanding

1) Proc file is the bit of older approaches. It allocates PAGE size memory on each read or write call and this system is over all buggy(Like you are reading/write proc entry of any device and device is removed from system..no handing of this in Proc system..{read it from LDD:) }). So kernel developer community suggest to use SYS file system which is more advance and sophisticated.

Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222