Linux Kernel module programming source code example-startup parameters

Source: Internet
Author: User
Linux Kernel module programming source code example-startup parameters-general Linux technology-Linux programming and kernel information, the following is a detailed description. Startup parameters

In many examples above, we have to hard write something like a kernel module, such as a file name in/proc or the device's master device number, so we can use ioctl for it. This is in conflict with the flexible program spirit that can be customized by users who write Unix and Linux.

Before a program or kernel module can start to work, you can tell it something you need through command line parameters. In the case of kernel modules, we cannot get the replacement of argc and argv. We get better things. We can define global variables in the kernel module and insmod will fill them for us.

In this kernel module, we define two: str1 and str2. All you need to do is compile the kernel module and run it with insmod str1 = xxx str2 = yyy. When the init_module is called, str1 points to the string 'xxx', and str2 points to 'yyy '.

These parameters 2.0 are not checked for type in version 6.1. If the first character of str1 or str2 is a number, the kernel fills the variable with an integer instead of a string pointer. In actual situations, you need to check this.

On the other hand, in version 2.2, you use the macro MACRO_PARM to tell insmod that you expect a parameter, its name and type. This solves the type problem and allows the kernel module to receive strings starting with numbers.


Example: param. c
QUOTE:
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.