Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically insert and remove kernel modules in C

Is there anyway to do "insmod" and "rmmod" from C/C++ code? Other than running system(...), is there a Kernel API that will allow me to do this?

like image 638
RishiD Avatar asked May 07 '10 19:05

RishiD


People also ask

How do I remove a module from a kernel?

To unload a kernel module, we use the rmmod (remove module) command.

What command is used to add or remove kernel modules?

modprobe command is used to add and remove module from the kernel.

Which command is used to add loadable kernel module?

Loadable kernel modules in Linux are loaded (and unloaded) by the modprobe command. They are located in /lib/modules or /usr/lib/modules and have had the extension . ko ("kernel object") since version 2.6 (previous versions used the .o extension).

What is the lsmod command used for?

The lsmod command is used to display the status of modules in the Linux kernel. It results in a list of loaded modules. lsmod is a trivial program which nicely formats the contents of the /proc/modules , showing what kernel modules are currently loaded.


2 Answers

Have you looked at the module-init-tools source?

like image 139
Nikolai Fetissov Avatar answered Oct 20 '22 19:10

Nikolai Fetissov


In addition to viewing the source for insmod and module-init-tools you could strace and ltrace a run of insmod.

like image 3
nategoose Avatar answered Oct 20 '22 20:10

nategoose