Operating Systems 2014F: Tutorial 7: Difference between revisions
Created page with "Test" |
No edit summary |
||
Line 1: | Line 1: | ||
In this tutorial you will be learning about the basics of Linux kernel modules and character devices. | |||
# Download the source for [this simple module]. | |||
==Source== | |||
===simple.c=== | |||
<source lang="c"> | |||
#include <linux/module.h> | |||
#include <linux/init.h> | |||
#include <linux/kernel.h> | |||
static int __init simple_init(void) | |||
{ | |||
printk ("Hello kernel world!\n"); | |||
return 0; | |||
} | |||
static void __exit simple_exit(void) | |||
{ | |||
printk ("Goodbye kernel world.\n"); | |||
return; | |||
} | |||
module_init(simple_init); | |||
module_exit(simple_exit); | |||
MODULE_LICENSE("GPL"); | |||
MODULE_AUTHOR("Anil Somayaji <soma@scs.carleton.ca>"); | |||
MODULE_DESCRIPTION("A simple module"); | |||
</source> | |||
===Makefile (for simple)=== | |||
<source lang="makefile"> | |||
obj-m := simple.o | |||
KDIR := /lib/modules/$(shell uname -r)/build | |||
PWD := $(shell pwd) | |||
default: | |||
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules | |||
</source> |
Revision as of 18:31, 11 November 2014
In this tutorial you will be learning about the basics of Linux kernel modules and character devices.
- Download the source for [this simple module].
Source
simple.c
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
static int __init simple_init(void)
{
printk ("Hello kernel world!\n");
return 0;
}
static void __exit simple_exit(void)
{
printk ("Goodbye kernel world.\n");
return;
}
module_init(simple_init);
module_exit(simple_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Anil Somayaji <soma@scs.carleton.ca>");
MODULE_DESCRIPTION("A simple module");
Makefile (for simple)
obj-m := simple.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules