Kernel module for / proc
How do I write a kernel module that creates a directory in / proc called mymod and the file in it is mymodfile. This file should accept a number between 1 and 3 when it is written and return the following messages when read based on the number already written to it:
• 1: current system time (microsecond precision)
• 2: System uptime
• 3: number of processes currently on the system.
"Exit"
root@Paradise# echo 1 > /proc/mymod/mymodfile
root@Paradise# cat /proc/mymod/mymodfile
08:30:24 342us
root@Paradise# echo 2 > /proc/mymod/mymodfile
root@Paradise# cat /proc/mymod/mymodfile
up 1 day, 8 min
root@Paradise# echo 3 > /proc/mymod/mymodfile
root@Paradise# cat /proc/mymod/mymodfile
process count: 48
please let me understand how to write kernel modules and how to compile and install them.
a source to share
What you are looking for is the Linux Kernel Modules Programming Guide , specifically on the / proc filesystem , which has well-documented examples of adding new entries.
a source to share
This month there is an article about it in a French magazine called "The Gnu / Linux Magazine".
I don't have my bookmarks, but the link theses look ok:
http://www.linuxhq.com/lkprogram.html
a source to share