How to get use count from Linux kernel module?
module_refcount()
will give you the use count of the module passed.
How to view information about a newly loaded external Linux kernel module?
From the man page:
modinfo extracts information from the Linux Kernel modules given on the command line. If the module name is not a filename, then the /lib/modules/version directory is searched, as is also done by
modprobe(8) when loading kernel modules.
So it looks like this command just uses the kernel module files to get this information, so you can either run:
modinfo hello.ko
or you could put your kernel module in the /lib/modules/version/
directory
Get Linux Kernel module name from current module
Inside the code of the kernel module, THIS_MODULE
points to the structure representing this module. You may use name
field of this structure for extract the current module name:
printk("Current module name: %s\n", THIS_MODULE->name);
If your code could be compiled (depending on configuration) either as a module or as a part of the kernel, then in the latter case THIS_MODULE
will be NULL, so you cannot access its fields. For such code you could use module_name
macro instead:
printk("Current module name: %s\n", module_name(THIS_MODULE));
Within the kernel core code (not a module) the macro is expanded to the string "kernel"
.
Related Topics
Compiler Can't Find Libxml/Parser.H
How to Open Remotely Installed Sonar on a Browser
How to Export Symbol from Linux Kernel Module in This Case
Shell Script to Kill the Process Listening on Port 3000
How to Start Tomcat with Output on Console in Linux
Using 'Find -Perm' to Find When a Permission Is Not Set
How to Add a Line to a File in a Shell Script
How to Find Hadoop Hdfs Directory on My System
Using Mkdir -M -P and Chown Together Correctly
How to Confirm Sftp File Delivery
"When" Condition on Ansible Playbook Doesn't Work as Expected Using Operators
How to Figure Out What Is Using a Linux Kernel Module
How to Make a Computer Behave as a Bluetooth Hid Device
How to Find Files Modified in Last X Minutes (Find -Mmin Does Not Work as Expected)
How to Recursively List All Directories at a Location, Breadth-First