Page 255 - DCAP403_Operating System
P. 255

Operating System




                    Notes          {
                                   printk(“init_module invokedn”);
                                   printk(“the message is printed from the kernel spacen”);
                                   / if the non zero value is returned, then it means 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 invokedn”);
                                   printk(“module is now going to be
                                   unloaded from the kerneln”);
                                   }
                                   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.

                                   Now check the status of the module using
                                   #lsmod
                                   Then remove the module using
                                   #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. dmesg |
                                   less In the above, 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’.
                                   Let’s now discuss the demand loading of the module by the kernel, dynamically. When the Linux
                                   kernel discovers the need for a module, the kernel requests to the kernel daemon (kerneld) to
                                   load the appropriate module. To illustrate this with an example, lets mount a NTFS partition in
                                   the Linux system. If the NTFS filesystem support is not statically implemented in the kernel (but

                                   compiled as a module), the kernel daemon will search for the appropriate module and load it
                                   from the repository. Then the partition is mounted for the use.
                                   Lets go deep into the action of the kernel daemon (kerneld). The kerneld is the normal user
                                   process having exclusive superuser privileges. At the time of booting, kerneld opens the IPC
                                   channel to the kernel and uses it for transferring messages (request for loading modules), to and
                                   from the kernel. While loading the module, the kerneld calls modprobe and insmod to load the
                                   required module. The insmod utility should able to access the requested module. The demand
                                   loadable kernel modules are usually located at/lib/module/directory as the object fi les linked
                                   as relocatable images.




          248                              LOVELY PROFESSIONAL UNIVERSITY
   250   251   252   253   254   255   256   257   258   259   260