Introduction to Linux Kernel Modules.2

Start article >>

/* Simple Linux Kernel Module feb’2000 */



/* initialise the module */
int init_module()
printk(”init_module invoked\n”);
printk(”the message is printed from the kernel space\n”);

/* if the non zero value is returned, then it is
meant that the init_module failed and the kernel module can’t
be loaded */

return 0;

/* cleanup / end of module life cycle */
void cleanup_module()
printk(”cleanup_module invoked\n”);
printk(”module is now going to be
unloaded from the kernel\n”);

Compile the above program using the following :

#gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -O -c simpelModule.c

Run the compiled module using the following :

#insmod simpleModule.o

Remember, you have to run the above command from the Linux shell at raw console (not from the console in Xwindows environment) at root login. Then check the status of the module using the following.


Then remove the module using the following

#rmmod simpleModule

If you have not seen any of the module initiated console printing (implemented using printk) about the status of the module, use the following command to see the kernel messages.

Elinext software development Company.

In the above, there commands (insmod, lsmod and rmmod ) are used to load and unload modules to the Linux kernel. The details are discussed in the following section. Loading Modules:insmod loads the loadable kernel modules in the running kernel. insmod tries to link a module into the running kernel by resolving all the symbols from the kernel’s exported symbol table. Now we will discuss about the demand loading of the module by the kernel (dynamically).

Leave a Reply

You must be logged in to post a comment.