Communication between Linux kernel and user space program

后端 未结 2 445
天涯浪人
天涯浪人 2021-02-01 00:03

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

相关标签:
2条回答
  • 2021-02-01 00:24

    Instead of using normal sockets, proc fs and implementing a new system call, Use netlink sockets which offers full duplex communication between user space programs and kernel modules.

    0 讨论(0)
  • 2021-02-01 00:37

    There are several ways to implement this.

    The easiest is to use the proc file interface to communicate, especially if the message and the result are less than one page in size.

    General Sequence would be as under:

    • Implement proc_open(), proc_read() and proc_write(); proc_close();
    • Open and close can implement locking so that only one instance of userspace program can actually access the module request engine.

    • the task request is sent via a write to the proc file,

    • The write function will return successfully if the module understands the command, before returning the program will initialize the request processing, the processing can actually take place when the proc file is read if it is trivial. If the processing is significantly complex then i suggest that you read up on bottom halves1 (you can simply start a working queue).

    • The read either triggers the "processing you want the module to do". or waits for the BH to finish the processing in case you do it that way. You can use a spinlock or a mutex to control flow.

    • The kernel processing returns the result upon completion.

    0 讨论(0)
提交回复
热议问题