"Linux operating system" Linux kernel insert unload module

Source: Internet
Author: User
Tags dmesg

    • Open Terminal
    • Input: mkdir moduletest, create a folder where files are placed
    • Go to folder, CD Moduletest
    • Create file: Nano hello.c, file contents are as follows:
#include <linux/init.h>#include <linux/module.h>MODULE_LICENSE("Dual BSD/GPL");staticint hello_init(void){    printk(KERN_ALERT"Hello, xiaoming\n");    return0;}staticvoid hello_exit(void){    printk(KERN_ALERT"Goodbye, xiaoming\n");}module_init(hello_init);module_exit(hello_exit);
    • Create Makefile file: Nano Makefile, code as follows:
obj-m := hello.oKERNELBUILD :=/usr/src/linux-headers-3.11.0-12-genericdefault:    make -C $(KERNELBUILD) M=$(shell pwd) modulesclean:    rm -rf *.o  *.ko *.mod.c .*.cmd.tmp_versions *.order *.symvers

The path inside is different from the Linux version, you can go to the corresponding path to see

    • Compile, enter make, and compile the process:

    • Insert module: sudo insmod Hello.ko

    • Delete module: sudo rmmod Hello.ko

    • View Results: DMESG | grep "Xiaoming"

      DMESG viewing system kernel module information

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Linux operating system" Linux kernel insert unload module

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.