Page 254 - DCAP403_Operating System
P. 254
Unit 13: Case Study: Linux
device drivers or pseudo-device drivers such as network drivers or file system. When a Linux Notes
kernel module is loaded, it becomes a part of the Linux kernel as the normal kernel code and
functionality and it posses the same rights and responsibilities as the kernel code.
Figure 13.1: Block Diagram of Linux Operating System
13.2.2 Life Cycle of Linux Kernel Module
The life cycle of a module starts with the init_module(). The task of init_module is to prepare the
module for later invocation. The module is registered to the kernel and attaches its data-structures
and functionality to the kernel. The kernel-defined external functions are also resolved. The life
cycle of the module ends with cleanup_module(). It `unregisters’ the module functionality from
the kernel.
Simple Module Program
Let us now program a simple module to review its life cycle. The init_module is called when the
module is inserted into the kernel where as the cleanup_module is called just before removing it
from the kernel. In the following program, the init_module and the cleanup_module functions
are demonstrated.
/* Simple Linux kernel module Feb’2001
#include
#include
#if CONFIG_MODVERSIONS==1
#define MODVERSINS
#include
#endif
/ initialise the module /
int init_module()
LOVELY PROFESSIONAL UNIVERSITY 247