Linux Device Driver code to load another module
Linux Kernel code can load module whenever needed.
int request_module(const char *module_name);
Header File: <linux/kmod.h>
Source Code: kernel/kmod.c
request_module is synchronous, it will sleep until the attemp to load the module has been completed.
When the kernel code calls request_mode(), a new kernel thread is created, which runs modprobe program in the user context.
Code:
Output:
int request_module(const char *module_name);
Header File: <linux/kmod.h>
Source Code: kernel/kmod.c
request_module is synchronous, it will sleep until the attemp to load the module has been completed.
When the kernel code calls request_mode(), a new kernel thread is created, which runs modprobe program in the user context.
Code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <linux/module.h> /* for MODULE_* */ | |
#include <linux/printk.h> /* for pr_info */ | |
static int __init mod_init(void) | |
{ | |
if (request_module("crc7") > 0) | |
pr_info("request_module failed to load\n"); | |
else | |
pr_info("request_module loaded successfully\n"); | |
return 0; | |
} | |
static void __exit mod_exit(void) | |
{ | |
} | |
module_init(mod_init); | |
module_exit(mod_exit); |
Output:
Comments
Post a Comment