Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if Linux Kernel Module is running

I wrote a kernel module that creates a entry in /proc/ and does some other tasks. I want to modify an existing kernel module to check if my module is running and execute some sentences depending on it (or execute others in case it is not running)

Any advice on how to do this?

like image 976
jeanc Avatar asked Mar 04 '26 10:03

jeanc


1 Answers

kernel/module.c provides a function that will probably do what you need; you first need to lock module_mutex and then call find_module() with the name of your module. The result will be a pointer to a 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);
like image 171
sarnold Avatar answered Mar 07 '26 00:03

sarnold



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!