使用 procfs 的 Linux 内核代码:我应该注意什么?
我对内核补丁有一个非常好的想法,我想在形成我的想法之前进行一些研究并查看代码示例。
我正在寻找有趣的代码示例来演示 procfs 的高级用法(Linux /proc< /code>
文件系统)。 我所说的有趣不仅仅是阅读记录的值。
我的想法是为每个进程提供一个简单的广播机制。 例如,让我们考虑一个运行多个 rsync
实例的进程并想要检查每个子项的传输状态(到目前为止已传输了多少字节)。 目前,我不知道有什么办法可以做到。
我打算为进程提供一个最小的接口来将数据写入 procfs
。 该数据将放置在 PID 目录下。 例如:
/procfs/1343/data_transfered/incoming
我可以想到这样做有很多优点,主要是在并发领域。
顺便说一句,如果这样的机制已经存在,请告诉...
I have a very nice idea for a kernel patch, and I want to conduct some research and see code examples before I shape my idea.
I'm looking for interesting code examples that would demonstrate advanced usage of procfs (the Linux /proc
file system). By interesting, I mean more than just reading a documented value.
My idea is to provide every process with an easy broadcast mechanism. For example, let's consider a process that runs multiple instances of rsync
and wants to check the transfer status (how many bytes have been transfered so far) for each child. Currently, I don't know of any way that can be done.
I intend to provide the process with a minimal interface to write data to the procfs
. That data would be placed under the PID directory. For example:
/procfs/1343/data_transfered/incoming
I can think of numerous advantage for this, mainly in the concurrency field.
By the way, if such a mechanism already exists, do tell...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,我已经写了一些在 /proc 中闲逛的东西。 我怀疑你不太可能接受对 proc 做任何事情的 Linux 内核补丁,除非它们只是修复已经存在的以某种方式损坏的东西。*
/sysfs 似乎是事情正在发生的地方。
/proc本来是进程信息,但是杂项很多。 司机的东西最终就在那里。
*好吧,如果您所做的任何事情都与进程有关并且不在驱动程序中,也许他们会接受它。
Yes, I've written stuff that pokes around in /proc. I suspect you are unlikely to get linux kernel patches accepted that do anything with proc, unless they are just fixing something that is already there that was broken in some way.*
/sysfs seems to be where things are moving.
/proc was originally for process information, but a lot of misc. driver stuff ended up in there.
*well, maybe they'll take it if whatever you're doing has to do with processes, and isn't in a driver.
查看 procps 包的源代码,了解使用 /proc 的代码
Go look at the source code for the procps package for code that uses /proc
http://github.com/tialaramex/leakdice/tree/master
使用 proc 来找出进程的内存地址布局,并从其堆中转储随机页面(其文档中解释了原因)。
http://github.com/tialaramex/leakdice/tree/master
Uses proc to figure out the memory address layout of a process, and dump random pages from its heap (for reasons which are explained in its documentation).