LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-26-2005, 10:18 PM   #1
kushneeraj
LQ Newbie
 
Registered: Oct 2005
Posts: 6

Rep: Reputation: 0
how to unload kernel module dynamically


Hi All

How can i automatic unload a kernel module...I know i can load the module automaticaly using request_module() but how to unload it.

Please help

thx
Neeraj
 
Old 10-26-2005, 11:46 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
1. The command-line tool to unload a module, of course, is "rmmod"

2. "google rmmod.c" =>
http://www.koders.com/c/fid53B502CEE...04232AB59.aspx

3. less rmmod.c =>
Code:
/* vi: set sw=4 ts=4: */
/*
 * Mini rmmod implementation for busybox
 *
 * Copyright (C) 1999,2000 by Lineo, inc.
 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#include "internal.h"
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#define __LIBRARY__



/* And the system call of the day is...  */
_syscall1(int, delete_module, const char *, name)


static const char rmmod_usage[] =
	"rmmod [OPTION]... [MODULE]...\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
	"\nUnloads the specified kernel modules from the kernel.\n\n"
	"Options:\n" 
	"\t-a\tTry to remove all unused kernel modules.\n"
#endif
	;



extern int rmmod_main(int argc, char **argv)
{
	if (argc <= 1) {
		usage(rmmod_usage);
	}

	/* Parse any options */
	while (--argc > 0 && **(++argv) == '-') {
		while (*(++(*argv))) {
			switch (**argv) {
			case 'a':
				/* Unload _all_ unused modules via NULL delete_module() call */
				if (delete_module(NULL)) {
					perror("rmmod");
					exit(FALSE);
				}
				exit(TRUE);
			default:
				usage(rmmod_usage);
			}
		}
	}

	while (argc-- > 0) {
		if (delete_module(*argv) < 0) {
			perror(*argv);
		}
		argv++;
	}
	return(TRUE);
}
So the answer to your question is "delete_module()".
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unload a module without rebooting? Phaethar Linux - Software 4 04-27-2005 12:42 PM
unload ub-module at boot? Urkburk Slackware 10 03-25-2005 05:35 AM
How can i force unload a module that is busy Doomhammer Linux - Software 1 03-23-2005 01:25 PM
Unable to unload eepro100 module in Kernel 2.6 simjii Linux - General 0 12-08-2003 11:50 PM
Unload wireless module (orinoco_cs)? coujeaux Linux - Wireless Networking 1 10-15-2003 11:48 AM


All times are GMT -5. The time now is 07:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration