> > The question is how to keep userland
> > application listening the requests from module all the
> > time? Using an infinite loop in userland application
> > just wastes too much processor time.
> The userland app should call select(2) to wait until there is data to be
> read from the device file. Busy-waiting is not necessary.
I hope I understand it right. Sorry for asking silly questions. I'm new in
Linux. Based on my understanding:
(1) since kernel module always starts the process first (requests data from,
or sends data to the userland application to get its processing result
back), so kernel module works as a client; while userland app works
as a server.
(2) userland application needs to do something like the following.
will block the process before the status is changed at /dev/mydevice.
This way, it's not busy-waiting anymore.
fd = open("/dev/mydevice");
select(fd...) //Block here until status is changed on /dev/mydevice
ch = read(fd); // Read in the request (a char) from module.
switch(ch) //Parse it and do things accordingly.
case 'r': //Need to read more data from module.
while(ch = read(fd) != '\0')
case 'w': //Need to write data to the module.
Quote:} //End of while loop
(3) I don't know what module should do to yet. I'll check. Could you
please give me a rough outline on what module should do?
It seems the module should have read() and write() routines to
interact with userland app's write() and read() functions, right?
Also I guess module code has nothing to do with /dev/mydevice.
mknod will create /dev/mydevice regardless what module I create.
And once /dev/mydevice is created and linked with the module by
mknod, all functions defined in the module can be used by an
userland application after open( ) the fd to /dev/mydevice, right?
(4) One question is that over 512 byte of data needs to be transferred
from/to module to/from the userland application everytime after
module starts the request. Is there any potential problem with this
mechanism to transfer so many bytes between kernel and userland
> > The kernel module is a firmware that gets loaded
> > everytime after reboot the hardware device. Is it
> > possible to get /dev/mydevice "installed" automatically
> > without using mknod manually?
> You only have to run mknod once, then the device file remains until it is
> deleted. Something (an install script or a person) has to run the mknod
> command once (as root).
(5) Do I need to run the mknod everytime after system reboot to create
/dev/mydevice? I guess this node will be lost after reboot.
> > Since I guess it's
> > not possible for a kernel module to load a userland
> > share lib (*.so). Am I right, or do I miss something?
> You are right. The kernel does not load shared libraries into a user
> program's address spaces. The application does it by calling mmap() to
> map the .so file into its virtual address space.
(6) Sounds like I need either link a static lib with the userland app, or
userland app to load a shared lib on the fly. Then module can get
the services defined in the lib indirectly through the userland app,
(7) Can I use a daemon, instead of a regular userland application, to
with a kernel module? What are the pros/cons if I use a daemon for
Many thanks for your help, and have a nice weekend!