I'm currently writing a Linux kernel module, and have problems implementing its communication with user space programs.
This kernel module needs to receive tasks issued by a user space program, and send results back to user space program after completion. The user space program should be blocked while the kernel module is doing its job.
I think a kernel-user space IPC or an Unix socket would be sweet, but I had no luck finding an example by Google.
Currently my ugly solution is to export a chardev
and let user space program write requests to the device file, and read results from it. But I can only issue one request per open()
call, and this is causing new problems. I really need an IPC or socket-like thing. Thanks!
chardev
sounds good to me. Why can you issue only one request per open(2)? Why not one request per write(2) and get results back with read(2)? The user process will be blocked in read(2) while your module is sending data. Where is your problem? – Mackie Messerwrite(2)
call has written a complete message. If the user program usesfprintf()
to write requests tochardev
, then the kernel module might receive partial messages. By using sockets or IPC, I think I could guarantee the message to be complete. – Santa Zhang