How To Make A Pseudo-File: As A Follow-Up To Our First Lab, We Examine The Steps Needed To Create Our Own /proc' File
How To Make A Pseudo-File: As A Follow-Up To Our First Lab, We Examine The Steps Needed To Create Our Own /proc' File
Open Source
Source text for the Linux kernel is on disk
(usual directory-location is /usr/src/linux)
Majority of the sources are written in C
(so portable across CPU architectures)
Some are written in assembly languages
(for nearly twenty different architectures)
Files are grouped into major categories
(kernel, mm, fs, net, ipc, lib, drivers, init)
You could edit and recompile your kernel
A minimal module-template
#include <linux/module.h>
int init_module( void )
{
// code here gets called during module installation
}
void cleanup_module( void )
{
// code here gets called during module removal
}
MODULE_LICENSE(GPL);
A non-trivial module-example
Lets see how we can use kernel functions
to create our own /proc file
Easy if we use create_proc_read_entry()
during module-initialization (and then use
remove_proc_entry() during cleanup)
Prototypes in the <linux/proc_fs.h> header
Well show the current value of a volatile
kernel variable, named jiffies
jiffies
In-class exercise #1
Use an editor (e.g., vi) to create a source
file in C (named jiffies.c) for your module
Use the make command to compile your
modules source-file into an object-file
Use the insmod command to install your
module object-file into the running kernel
Use the cat command to display jiffies
Then use rmmod to remove your module
Makefile
Rule syntax
targets:dependencies
commands
...
In-class exercise #2
Use your knowledge of standard C library
functions (e.g., open(), read(), close() ) to
write an application-program (name it
showjifs.cpp) which reads the information
from your proc/jiffies pseudo-file and then
prints it on the screen
Use a program-loop to re-read the pseudo
file multiple times
How rapidly does jiffies value increase?