Linux / proc kernel FIFO / pipe

I am currently trying to create a kernel module that will generate data based on kernel events and insert them into a file. After reading that this is bad (and I agree), I decided that it would be wiser to have data in the / proc file that the user program could extract when necessary. However, this idea led to various problems, especially when and how to clean this file. So I thought ... "Why don't I make a named pipe in / proc and read from that?"

I have a common sense in setting up the read function and the write function for the proc file, but I still have conceptual problems with how I will deal with this. Namely, how could I write such a function to receive arbitrary data and write it to such a channel from the kernel? Does anyone know how you will transfer data to a named pipe from kernel space? In the end, it does not have to be the / proc file (especially if it is wrong for me), but it was the conclusion I came to. Then I will have to figure out how to connect to it from the user program, but I feel that this is a separate issue.

+2
linux pipe kernel procfs fifo
source share
4 answers

Instead of creating a named pipe, what you want to do is create a "character device." If you need simple interaction or streaming data from the kernel to user space and vice versa, this is the usual method. I would recommend looking for similar devices in the Linux kernel and see what they do.

+5
source share

I think that, as a rule, this is done to use the netlink socket; one or more processes in user space can bind to the netlink address, and your kernel facility can send messages to all / all of them as needed.

This, of course, is what some do, the network subsystem. Using this method, a user-space program can track changes to network interfaces (for example, new IP addresses, link status changes).

+3
source share

I agree with Paul - introducing a character device is probably the best way. Perhaps look at the implementation of the code / dev / kmem or / dev / rtc [0-9]. In addition, serial drivers implement their drivers using character devices.

Just think of it as a virtual device. :-)

+1
source share

/ proc is not really a real file system ; it is built by the core based on what is currently working. I don’t think you can create named pipes in it.

+1
source share

All Articles