Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose between "sys' and "proc" files in linux kernel

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.

like image 774
Jeegar Patel Avatar asked Dec 07 '15 12:12

Jeegar Patel


Video Answer


2 Answers

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.

like image 123
mkmk88 Avatar answered Nov 13 '22 07:11

mkmk88


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.

like image 27
Jeegar Patel Avatar answered Nov 13 '22 09:11

Jeegar Patel