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

此生再无相见时 提交于 2020-08-02 07:33:20

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/34133497/how-to-choose-between-sys-and-proc-files-in-linux-kernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!