Check if the Linux kernel module is running… here is a solution to the problem.
Check if the Linux kernel module is running
I wrote a kernel module that creates an entry in /proc/ and performs some other tasks.
I want to modify an existing kernel module to check if my module is running and execute some statements based on it (or others if it is not).
Any suggestions on how to do this?
Solution
kernel/module.c
provides a feature that might meet your needs; You first need to lock the module_mutex
and then call find_module()
with your module name. The result will be a pointer to the struct
module that describes the named module – or NULL
: if the module is not loaded
/* Search for module by name: must hold module_mutex. */
struct module *find_module(const char *name)
{
struct module *mod;
list_for_each_entry(mod, &modules, list) {
if (strcmp(mod->name, name) == 0)
return mod;
}
return NULL;
}
EXPORT_SYMBOL_GPL(find_module);