LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (http://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   "insmod inserted the LKM into the kernel, But rmmod not removing it back" (http://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/insmod-inserted-the-lkm-into-the-kernel-but-rmmod-not-removing-it-back-4175419281/)

SIG_SEGV 07-30-2012 12:12 AM

"insmod inserted the LKM into the kernel, But rmmod not removing it back"
 
I am learning Kernel module programming and so have tried for the simple example.
#include <asm/current.h>
#include <linux/sched.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static void pro_init(void)
{
printk (KERN_ALERT "The process is \"%s\" (pid %i)\n",current->comm, current->pid);
}

static void pro_exit(void)
{
printk (KERN_ALERT "The process has exited\n");
}
module_init(pro_init);
module_exit(pro_exit);

The program worked with no problems. But when i removed off the last 2 lines of kernel_macros, recompiled the module and inserted it back to the kernel, The module was successfully inserted. lsmod shows the inserted module. Now when i try to unlink the module by 'rmmod' it says 'device/resource busy'.

How come the kernel now is in need of clean_up (module_exit) macro where it didn't bother of 'module_init' macro when i used insmod to insert the module....???

business_kid 07-31-2012 04:59 AM

sudo rmmod -f ?

SIG_SEGV 07-31-2012 05:47 AM

No, I have actually found the solution for the problem. It was 'my program lacked with a cleanup module (module_exit(--)) in the end. But my question is.......

"How come the kernel now is in need of clean_up (module_exit) macro. Because it didn't bother of 'module_init' macro when i used insmod to insert the module without (module_init)....???"

business_kid 07-31-2012 10:17 AM

It should be obvious - rescue allocated resources, etc.


All times are GMT -5. The time now is 01:17 PM.