"Finishing"--linux simple kernel module development

Source: Internet
Author: User

1. Linux kernel modules are not compiled into kernel files (zimage,bzimage), but are dynamically installed and uninstalled during runtime

2, the kernel module includes a few parts: main part design, compile kernel module, install uninstall NHMK, optional use (module declaration, MK parameter, symbol output)

3, simple example:

HELLO.C:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

Module_license ("Dual BSD/GPL");

static int hello_init (void)
{
PRINTK (kern_alert "hello_init \ n");
return 0;
}

static void Hello_exit (void)
{
PRINTK (Kern_alert "goodbye,kernel!\n");
}

Module_init (Hello_init);
Module_exit (Hello_exit);

Module_author ("APOLLO"); Author
Module_description ("This was a simple example\n"); Module description
Module_alias ("A Simple Example"); Alias

Makefile:

obj-m:=hello.o
PWD: = $ (shell pwd)

kdir:=/lib/modules/3.13.0-45-generic/build/

All
Make-c $ (Kdir) m=$ (PWD) modules
Clean
RM-RF *.mod.c *.mod.o *.ko *.o *.tmp_versions *.order *symvers

"Finishing"--linux simple kernel module development

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.