Linux Kernel Module Programming — Simplest example

  • C programming language
  • Makefiles
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Sachith Muhandiram");
MODULE_DESCRIPTION("Simple first Linux module");
MODULE_VERSION("1.0.0");
static int __init initHelloWorld(void){
printk(KERN_INFO "Hello, this is my first kernel module \n");
return 0;
}
static void __exit exitHelloWorld(void){
printk(KERN_INFO "Exit Hello world module\n");
}
module_init(initHelloWorld);
module_exit(exitHelloWorld);
obj-m += hello.oall:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store