You are on page 1of 5

How to write a simple kernel module in linux (centOS 7)?

STEPS:-

1) To create development environment in centOS 7

# yum group install "Development Tools"

2) Create a directory.

mkdir usr/local/src/kernel_example
cd usr/local/src/kernel_example

3)vi and create the file kernel_example.c with the following contents:

$vi kernel_example.c
We call module_init and module_exit to tell the kernel which

functions are loading and unloading functions.We can’t compile this

file yet, though.

We need a Makefile.

$vi Makefile
The resulting file is “anjali_example.ko”.
we can insert the module to test it

$sudo insmod anjali_example.ko

$ dmesg

You might also like