Compiling and Testing hello_world

To compile the preceding source code, create the following makefile:

obj-m += hello_world.o

Compile by running make:

[notoot]$ make -C /usr/src/linux-`uname -r` SUBDIRS=$PWD modules
make: Entering directory `/usr/src/linux-2.6.8
  CC [M]  /tmp/lkms/hello_world.o
  Building modules, stage 2.
  MODPOST
  CC      /tmp/lkms/hello_world.mod.o
  LD [M]  /tmp/lkms/hello_world.ko
make: Leaving directory `/usr/src/linux-2.6.8

Run the insmod tool to load the module:

[root]# insmod ./hello_world.ko
Hello World!

List loaded LKMs using the lsmod tool:

[root]# lsmod
Module                  Size  Used by
helloworld              2432  0

Remove the module by using the rmmod tool:

[root]# rmmod hello_world
Good Bye!

Get Network Security Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.