Example of communication between kernel module and user application
Workflow:
- Kernel module invokes user application by calling call_usermodehelper
- User app sends some message to kernel
- Kernel receives message and sends response
- User app receives kernel-response and sends something back
First of all prepare a testing environment (maybe a virtual machine), because kernel modules may be very dangerous
make
All build artifacts (kernel module and user app) will be placed into the 'build' directory
Now insert the module
cd build
sudo insmod kernel_mod.ko
Show last ten log messages
dmesg -T | tail
If everything's fine you will receive something like this:
[19:39:05 2020] User app path: /home/owl/my/cpp/test_module/build/user_app
[19:39:05 2020] Launch with option: Wake up!
[19:39:05 2020] Message from user(pid 7187) : Hello kernel, you heartless bitch!
[19:39:05 2020] Send message back: Goodbye!
[19:39:05 2020] Message from user(pid 7187) : Goodbye kernel!
There is an additional logfile from user app in build directory.
Do cleanup
make clean
sudo rmmod kernel_mod.ko
Tested on 5.4.0