Linux kernel kernel_ nuclear travel_ Travel Linux kernel
Linux 2.6
1
Hellomod.c
001
Hello World driver for Linux 2.6
#include <linux/module.h>/* All modules use header files module.h*/
#include <linux/kernel.h>/*kernel.h contains common kernel functions */
#inlcude <linux/init.h>/* init.h contains macros _init and _exit they allow free memory */
/* Header File */
Static Int_init lkp_init (void)
{
PRINTK ("<1>hello,world! From the kernel space ... \ n "); /* Module initialization, PRINTK function
Equivalent to the printf output function in c,<1> immediate output */
return 0;
}
Static Void_exit lkp_cleanup (void)
{
PRINTK ("<1>goodbye,world! Leaving kernel space...\n ");
}
Module_init (Lkp_init); /* Entry point */
Module_exit (Lkp_cleanup); /* loadable module, the kernel calls the Lkp_cleanup function here */
Module_license ("GPL"); /* Hint no GNU Public License */
Module_init () and Cleanup_exit
Module_init () New functionality provided to the kernel to register the module
Cleanup_exit () Logout of new features provided by the module
C Language Application kernel module program
Using Functions libc Library kernel functions
Run space user space kernel space
Run permissions for normal user Super User
Entry function Main () Module_init ()
Exit Function exit () Module_exit ()
Compiling gcc-c Makefile
Connecting GCC Insmod
Run Direct Run Insmod
Debug Gdb kdbug kdb kgdb
This article is from the "No Regrets Wave" blog, please be sure to keep this source http://945884992.blog.51cto.com/9765680/1682089
Linux kernel Linux kernel travel