Linux kernel Linux kernel travel

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.