Linux kernel /proc FIFO/pipe

爱⌒轻易说出口 提交于 2019-12-04 17:45:28

Instead of making a named pipe, what you want to do is create a "Character device". If you want simple interaction or streaming data from kernel to userspace and back, this is the usual method. I'd recommend looking up similar devices in the Linux kernel and seeing what they do.

I think the way this is generally done is to use a netlink socket; one or more userspace processes can bind to a "netlink" address, and your kernel facility can broadcast messages to any / all of them as necessary.

This is certainly what some things do, the networking subsystem especially. It is possible for a userspace program to watch for changes in network interfaces (e.g. new IP addresses, link status change) using this method.

I agree with Paul—implementing a character device is probably the best way to go. Maybe looking at the code implementing /dev/kmem or /dev/rtc[0-9]. Also, the serial drivers implement their drivers using character devices.

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

/proc isn't actually a real file system; it's constructed by the kernel based on what's currently running. I don't think you can create named pipes in it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!