1 .\" Copyright (C) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .TH DELETE_MODULE 2 2012-10-24 "Linux" "Linux Programmer's Manual"
25 delete_module \- unload a kernel module
28 .BI "int delete_module(const char *" name ", int " flags );
32 There is no glibc wrapper for this system call; see NOTES.
36 system call attempts to remove the unused loadable module entry
41 function, then that function is executed before unloading the module.
44 argument is used to modify the behavior of the system call,
46 This system call requires privilege.
48 Module removal is attempted according to the following rules:
50 If there are other loaded modules that depend on
51 (i.e., refer to symbols defined in) this module,
54 Otherwise, if the reference count for the module
55 (i.e., the number of processes currently using the module)
56 is zero, then the module is immediately unloaded.
58 If a module has a nonzero reference count,
59 then the behavior depends on the bits set in
61 In normal usage (see NOTES), the
63 flag is always specified, and the
65 flag may additionally be specified.
66 .\" O_TRUNC == KMOD_REMOVE_FORCE in kmod library
67 .\" O_NONBLOCK == KMOD_REMOVE_NOWAIT in kmod library
69 The various combinations for
71 have the following effect:
74 .B flags == O_NONBLOCK
75 The call returns immediately, with an error.
77 .B flags == (O_NONBLOCK | O_TRUNC)
78 The module is unloaded immediately,
79 regardless of whether it has a nonzero reference count.
81 .B (flags & O_NONBLOCK) == 0
86 the following steps occur:
89 The module is marked so that no new references are permitted.
91 If the module's reference count is nonzero,
92 the caller is placed in an uninterruptible sleep state
93 .RB ( TASK_UNINTERRUPTIBLE )
94 until the reference count is zero, at which point the call unblocks.
96 The module is unloaded in the usual way.
102 flag has one further effect on the rules described above.
104 attempting to remove a module that has an
111 was specified, this requirement is bypassed.
116 If the kernel was not built with
117 .BR CONFIG_MODULE_FORCE_UNLOAD ,
118 this flag is silently ignored.
120 .BR CONFIG_MODULE_FORCE_UNLOAD
122 Using this flag taints the kernel (TAINT_FORCED_RMMOD).
124 On success, zero is returned.
125 On error, \-1 is returned and
127 is set appropriately.
131 The module is not "live"
132 (i.e., it is still being initialized or is already marked for removal);
146 refers to a location outside the process's accessible address space.
149 No module by that name exists.
152 The caller was not privileged
156 or module unloading is disabled
158 .IR /proc/sys/kernel/modules_disabled
163 Other modules depend on this module;
168 but the reference count of this module is nonzero and
176 Glibc does not provide a wrapper for this system call; call it using
179 The uninterruptible sleep that may occur if
183 is considered undesirable, because the sleeping process is left
184 in an unkillable state.
185 As at Linux 3.7, specifying
187 is optional, but in future kernels it is likely to become mandatory.
188 .SS Linux 2.4 and earlier
189 In Linux 2.4 and earlier, the system call took only one argument:
191 .BI " int delete_module(const char *" name );
195 is NULL, all unused modules marked auto-clean are removed.
197 Some further details of differences in the behavior of
199 in Linux 2.4 and earlier are
201 currently explained in this manual page.
203 .BR create_module (2),
205 .BR query_module (2),