Kernel Space / User Space bi-directional communication


New Member

Messages: 14


Just looking for some guidance, I want the kernel to be able to send data to a userspace program (daemon?) and for the daemon to process that data and return the processed data back to the kernel.

What ways in [Free]BSD are there for doing this? I've seen a lot about netlink and such for Linux but unsure about Unix.

Thanks in advance



Reaction score: 16
Messages: 58

One option is the way the Security Event Auditing system is implemented. The kernel sends data to the audit daemon (auditd) via the special device /dev/audit. Any user space program can send audit-related data to the kernel via the audit system calls. Even if user space programs need to send data to the daemon they will have to go through the kernel.

Check out sys/security/audit/* for the kernel part as well as contrib/openbsm/bin/auditd/* for the daemon sources.


Well-Known Member

Reaction score: 138
Messages: 337

There are a couple of options that come to mind.

1. A KLM that creates a character device on /dev and have the program read/write to that device.
2. A KLM that implements a new system call. Then you can use functions like copyin(9), copyinstr(9), and copyout(9) to pass data back and forth between user space and kernel space.

If you are going to spontainiously write data to the userland program from the kernel, then you will need to signal the program by either passing a message to it or sending a signal which your program will have to catch. Take a look at signal(3) and sigaction(2) for more info.


New Member

Reaction score: 1
Messages: 4

I know this is an old thread, but for the sake of reference if anyone reading this later on is interested, I have implemented a kernel module and a userland library that does exactly what the OP has asked for.

It provides a shared-memory based bi-directional communication mechanism between kernel / modules and a userland process.