Section (2) delete_module
delete_module — unload a kernel module
||const char *name,|
|No declaration of this system call is provided in glibc headers; see NOTES.|
call attempts to remove the unused loadable module entry
If the module has an
exit function, then that
function is executed before unloading the module. The
flags argument is
used to modify the behavior of the system call, as described
below. This system call requires privilege.
Module removal is attempted according to the following rules:
If there are other loaded modules that depend on (i.e., refer to symbols defined in) this module, then the call fails.
Otherwise, if the reference count for the module (i.e., the number of processes currently using the module) is zero, then the module is immediately unloaded.
If a module has a nonzero reference count, then the behavior depends on the bits set in
flags. In normal usage (see NOTES), the
O_NONBLOCKflag is always specified, and the
O_TRUNCflag may additionally be specified.
The various combinations for
flagshave the following effect:
- flags == O_NONBLOCK
The call returns immediately, with an error.
The module is unloaded immediately, regardless of whether it has a nonzero reference count.
- (flags & O_NONBLOCK) == 0
flagsdoes not specify
O_NONBLOCK, the following steps occur:
The module is marked so that no new references are permitted.
If the module_zsingle_quotesz_s reference count is nonzero, the caller is placed in an uninterruptible sleep state (
TASK_UNINTERRUPTIBLE) until the reference count is zero, at which point the call unblocks.
The module is unloaded in the usual way.
O_TRUNC flag has one
further effect on the rules described above. By default, if a
module has an
function but no
exit function, then an
attempt to remove the module fails. However, if
O_TRUNC was specified, this requirement is
O_TRUNC flag is
dangerous! If the kernel was not built with
CONFIG_MODULE_FORCE_UNLOAD, this flag is
silently ignored. (Normally,
CONFIG_MODULE_FORCE_UNLOAD is enabled.)
Using this flag taints the kernel (TAINT_FORCED_RMMOD).
The module is not live (i.e., it is still being initialized or is already marked for removal); or, the module has an
initfunction but has no
O_TRUNCwas not specified in
namerefers to a location outside the process_zsingle_quotesz_s accessible address space.
No module by that name exists.
The caller was not privileged (did not have the
CAP_SYS_MODULEcapability), or module unloading is disabled (see
Other modules depend on this module; or,
O_NONBLOCKwas specified in
flags, but the reference count of this module is nonzero and
O_TRUNCwas not specified in
call is not supported by glibc. No declaration is provided in
glibc headers, but, through a quirk of history, glibc
versions before 2.23 did export an ABI for this system call.
Therefore, in order to employ this system call, it is (before
glibc 2.23) sufficient to manually declare the interface in
your code; alternatively, you can invoke the system call
The uninterruptible sleep that may occur if
O_NONBLOCK is omitted from
flags is considered
undesirable, because the sleeping process is left in an
unkillable state. As at Linux 3.7, specifying
O_NONBLOCK is optional, but in future
kernels it is likely to become mandatory.
Linux 2.4 and earlier
In Linux 2.4 and earlier, the system call took only one argument:
const char *name);
name is NULL,
all unused modules marked auto-clean are removed.
Some further details of differences in the behavior of
delete_module() in Linux 2.4
and earlier are
not currently explained in
this manual page.
This page is part of release 4.16 of the Linux
man-pages project. A
description of the project, information about reporting bugs,
and the latest version of this page, can be found at
Copyright (C) 2012 Michael Kerrisk <mtk.manpagesgmail.com>
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Since the Linux kernel and libraries are constantly changing, this
manual page may be incorrect or out-of-date. The author(s) assume no
responsibility for errors or omissions, or for damages resulting from
the use of the information contained herein. The author(s) may not
have taken the same level of care in the production of this manual,
which is licensed free of charge, as they might when working
Formatted or processed versions of this manual, if unaccompanied by
the source, must acknowledge the copyright and authors of this work.