views:

187

answers:

3

Hi,

Have you ever written (or encountered) code that uses the procfs (the Linux /proc file system) in non-trivial ways?

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.

Udi

EDIT I'm looking for interesting code examples that would demonstrate advanced usage of the procfs. By non-trivial 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...

(Thanks, Neil!)

+1  A: 

Go look at the source code for the procps package for code that uses /proc

nos
+3  A: 

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.

smcameron
+1  A: 

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).

tialaramex