Kernel "Hello World"
Keywords: Linux kernel Hello World Wide288 Linuxfire
This article is the note on the compilation platform of the kernel module on the Debian GNU / Linux operating system. Now I want to help the friends you need. If you have inaccurate, please ask your friends.
My kernel version is: 2.4BF
First we need to install the header file of the kernel code, execute the command:
Apt-get install kernel-headers-2.4
(I can't remember the name of the detailed, please don't say that I am not responsible, this is the error of 9CBS, because use Mozilla can't publish a document.) But everyone can use the Tab key to make up the full package name.
After that, we entered the original code: ------------------------------------------- -
#define module
#include
INT init_module (void) {Printk ("<1> Hello, World / N); Return 0;} void cleanup_module (void) {Printk (" <1> Goodbye cruel world / n ");} ----- ---------- use commands to compile:
GCC -C Hello.c
Let's take a look at whether we have the files we want under the current directory.
LS -A
Is there helpo.o if it is right. This is the file we compiled. This file (module) is added to the kernel below. Excuting an order:
Insmod ./HELLO.O
There may be an error tip, but it doesn't matter, I have not found it affects normal use. There may be in the future. Error tips are:
WARNING: Loading Hello.o Will Taint The Kernel: No Licenssee http://www.tux.org/lkml/#Export-tainted for Information About Tainted ModulesModule Hello Loaded, with Warnings
Let's take a look at the display of this module, which is not displayed on the terminal. To execute the command:
Dmesg
Come check. At the bottom. There is also a way to see if this module is loaded successfully.
$ CAT / Proc / Modules
You can see the Hello module, this is what I loaded. The information in this file is divided into four columns. First column: Module name. 2: The module uses the number of bytes of memory. Third column: The current usage count of the module. The fourth column: Remarks. Ok, let's uninstall this module.
RMMOD Hello
Use DMESG to see the information sent when uninstalling.