Load modules in Linux Kernel

Source: Internet
Author: User
Load the module in the Linux kernel-general Linux technology-Linux programming and kernel information. The following is a detailed description. I saw how to write a driver in LINUX some time ago.

Today I wrote a try.

Write a simple small program
# Include "linux/kernel. h"
# Include "linux/module. h"
# Include "linux/version. h"
# If CONFIG_MODBERSIONS = 1
# Define MODBERSIONS
# Include "Linux. modversions. h"
# Endif
# Define devicename mydevice
MODULE_LICENSE ("GPL"); // here is a certificate for this module
/* The init funcion */
Int init_module ()
{

// Load the function of the module
Printk ("holy shit works! \ N ");

// Because PRINTF cannot work, use PRINTK. You can see the content here only by running the DMESG command.

Return 0;
}

/* The funcion which the device will be used */

Int cleanup_module ()
{

// Clear functions of the module
Printk ("holy shit works too !! \ N ");
Return 0;
}


Most of them are COPY, but I still understand it.

Compile the program after writing it. No makefile is prepared. replace it with a command.

Gcc-Wall-DMODULE-D_KENNEL _-DLinux-c test. c
I do not know the specific meaning

Compile and generate. Test. o

Then load the module with insmod test. o

An error may occur.

1. The module version is incorrect.

Solution: Modify/USR/INCLUDE/LINUX/VERSION. H. The # define UTS_RELEASE "2.4.18-3"

2. No certificate

MODULE_LICENSE ("GPL ");

3. Module busy

First, check whether the returned value of your loaded module is 0. If it is not 0, this error will certainly occur.

Use lsmod to check whether a module with the same name is running.

If yes, run the rmmod command to kill him.

4. No output is visible.

Output DMESG on the console.
Related Article

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.