Re: /proc file to user space daemon howto

Robert G. Brown (rgb@phy.duke.edu)
Mon, 23 Aug 1999 08:36:23 -0400 (EDT)


On Sun, 22 Aug 1999, Matthew wrote:

>
> I'm writing a program in which I set up several /proc files. The output of
> these files have to be passed from a user space daemon. Can someone point to
> some code that will give me some clues. I already have the /proc files set
> up, now I need to know how to alert the user space daemon at the point of a
> read request, and how to redirect a text stream from the daemon through the
> /proc file. --
>
> Thanks,
>

As I pointed out a few days ago, I've written a procstatd that can be
run as an inetd or forking daemon, with no special privileges -- it can
be run just fine from userspace.

The code is heavily commented, and should provide lots of examples on
how best to read from /proc files on a poll basis. There isn't anything
particularly fancy about it -- open it as if it is an ordinary file,
read it a line at a time, parse it or dump it or whatever. For files
with more than one line one can then rewind (and save the overhead of a
close/open) and read the then-current contents at a later time over and
over again. For files with just a single line, rewind() doesn't seem to
work (which seems to be a bug, although I'm not sure exactly where the
bug lies -- in the rewind() library function or the /proc setup) -- one
has to close/open to repeatedly read the file.

The procstatd code (and an accompanying monitor application) can be
retrieved from:

http://www.phy.duke.edu/brahma/procstatd.tar.gz

rgb

Robert G. Brown http://www.phy.duke.edu/~rgb/
Duke University Dept. of Physics, Box 90305
Durham, N.C. 27708-0305
Phone: 1-919-660-2567 Fax: 919-660-2525 email:rgb@phy.duke.edu

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/