Linux Kernel module

Source: Internet
Author: User

Lsmod actually reads and analyzes the/proc/modules File

cat /proc/modules 

Information about the loaded modules in the kernel exists in/sys/modules. /sys/module is a sysfs directory level that contains information about the currently loaded modules. /proc/moudles is an old-style version of a single file with that information. the entry contains the module name, memory usage of each module, and usage count. in addition, the string is appended to the end of each line to specify the flag. This module is currently active.

Linux Kernel module program structure

1) load the function (generally required)

When the kernel module is loaded through insmod or modprobe, the module's loading function is automatically executed by the kernel.

Static int _ init initialization_function (void) {/* initialization Code */} module_init (initialization_function );

2) uninstall the function (generally required)

When the module is uninstalled through rmmod or modprobe-R.

Static int _ init cleanup_function (void) {/* release code */} module_exit (cleanup_function );

3) module license statement (required)

If the license is not declared, the kernel is contaminated when the module is loaded.

MODULE_LICENSE("GPL"); 

Optional license: "GPL", "GPL V2", "GPL and additional rights", "dual BSD/GPL ",

"Dual MPL/GPL", "proprietary ".

4) module parameters (optional)

module_param(parm, parm_type, module_flags); 

If the permission permits, you can view the module parameters under/sys/modules/module_name/parameters.

5) module export symbol (optional)

Export_symbol (symbol name); export_symbol_gpl (symbol name );

6) module author and other information (optional)

MODULE_AUTHOR(author);MODULE_DESCRIPTION(description);MODULE_VERSION(version_string);MODULE_DEVICE_TABLE(table_info);MODULE_ALIAS(alternate_name);

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.