On Monday 16 December 2002 18:49, Chris Wright wrote: > * Ahmed A (ahmedcali@yahoo.com) wrote: > > Hi, > > <snip> > typically via sockets (AF_INET or AF_UNIX), named pipes, messsage <snip> Speaking of named pipes, is there a good online description on how to use them? I've had trouble in the past writing to named pipes when a SIGIO signal occurs, and it would be nice to find some sample code. Note: I believe that SIGIO on named pipes isn't implemented in linux until the 2.5.20 kernel. The daemon I'd like to write gathers information from several sources. The daemon should create a named pipe when a new source becomes available. When a user wants to see the most current information about a particular source he should be able to use the "cat" utility to read the data from the pipe that corresponds to the source he's interested in. Sources will not come up and go down very often, but they will do so without warning. The information from each source may change as often as every few seconds to every few minutes. I think that using SIGIO on the named pipes is the proper way to approach the problem, but I haven't been able to get it to work correctly. The daemon only gets the signal _after_ the user reads data from the pipe, not when he first attempts to read from it. A kludge is to write some dummy "header" information to each pipe, so when the user reads from a pipe, SIGIO occurs in the daemon and he knows to write the most recent data to the pipe. However, the problem now is that the "cat" program doesn't know when the daemon is finished sending data. Here's what happens before kludging (assuming the pipes are already set up): (1) user reads from empty pipe and hangs (2) daemon doesn't receive signal, so he never sends data to pipe (3) user hangs forever Here's what happens with the kludge: (1) daemon writes dummy data to pipe (2) user "cat" utility reads and displays dummy header from pipe (3) user "cat" waits around for more data (4) daemon gets signal, writes most recent data to pipe (5) user "cat" reads and displays data (6) user hangs forever, waiting for more data that never comes Here's what I'd like to have happen: (1) user reads from empty pipe (2) daemon gets signal, writes most recent data to pipe (3) user "cat" reads and displays data (4) user "cat" dies cleanly once pipe is empty Presumably this kind of problem has been handled before. For what it's worth, displaying the data using the /proc filesystem works very nicely if the code is written in kernel space. (Thank you, Erik Mouw, for the _Linux Kernel Procfs Guide_.) In the kernel, the function for displaying the data gets called when a user reads /proc/<sourcename>, and it displays only the most recent data. However, this code doesn't have any business being in the kernel. I would like a user space daemon to create named pipes that behave similarly. James -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/