]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/reboot.2
reboot.2: Johannes Liebermann <johanan.liebermann@gmail.com>
[thirdparty/man-pages.git] / man2 / reboot.2
1 .\" Copyright (c) 1998 Andries Brouwer (aeb@cwi.nl), 24 September 1998
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
26 .\" Added notes on capability requirements
27 .\"
28 .TH REBOOT 2 2017-09-15 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 reboot \- reboot or enable/disable Ctrl-Alt-Del
31 .SH SYNOPSIS
32 /* Since kernel version 2.1.30 there are symbolic names LINUX_REBOOT_*
33 for the constants and a fourth argument to the call: */
34 .PP
35 .B #include <unistd.h>
36 .br
37 .B #include <linux/reboot.h>
38 .PP
39 .BI "int reboot(int " magic ", int " magic2 ", int " cmd ", void *" arg );
40
41 /* Under glibc and most alternative libc's (including uclibc, dietlibc,
42 musl and a few others), some of the constants involved have gotten
43 symbolic names RB_*, and the library call is a 1-argument
44 wrapper around the system call: */
45 .PP
46 .B #include <unistd.h>
47 .br
48 .B #include <sys/reboot.h>
49 .PP
50 .BI "int reboot(int " cmd );
51 .SH DESCRIPTION
52 The
53 .BR reboot ()
54 call reboots the system, or enables/disables the reboot keystroke
55 (abbreviated CAD, since the default is Ctrl-Alt-Delete;
56 it can be changed using
57 .BR loadkeys (1)).
58 .PP
59 This system call fails (with the error
60 .BR EINVAL )
61 unless
62 .I magic
63 equals
64 .B LINUX_REBOOT_MAGIC1
65 (that is, 0xfee1dead) and
66 .I magic2
67 equals
68 .B LINUX_REBOOT_MAGIC2
69 (that is, 672274793).
70 However, since 2.1.17 also
71 .B LINUX_REBOOT_MAGIC2A
72 (that is, 85072278)
73 and since 2.1.97 also
74 .B LINUX_REBOOT_MAGIC2B
75 (that is, 369367448)
76 and since 2.5.71 also
77 .B LINUX_REBOOT_MAGIC2C
78 (that is, 537993216)
79 are permitted as values for
80 .IR magic2 .
81 (The hexadecimal values of these constants are meaningful.)
82 .PP
83 The
84 .I cmd
85 argument can have the following values:
86 .TP
87 .B LINUX_REBOOT_CMD_CAD_OFF
88 .RB ( RB_DISABLE_CAD ,
89 0).
90 CAD is disabled.
91 This means that the CAD keystroke will cause a
92 .B SIGINT
93 signal to be
94 sent to init (process 1), whereupon this process may decide upon a
95 proper action (maybe: kill all processes, sync, reboot).
96 .TP
97 .B LINUX_REBOOT_CMD_CAD_ON
98 .RB ( RB_ENABLE_CAD ,
99 0x89abcdef).
100 CAD is enabled.
101 This means that the CAD keystroke will immediately cause
102 the action associated with
103 .BR LINUX_REBOOT_CMD_RESTART .
104 .TP
105 .B LINUX_REBOOT_CMD_HALT
106 .RB ( RB_HALT_SYSTEM ,
107 0xcdef0123; since Linux 1.1.76).
108 The message "System halted." is printed, and the system is halted.
109 Control is given to the ROM monitor, if there is one.
110 If not preceded by a
111 .BR sync (2),
112 data will be lost.
113 .TP
114 .BR LINUX_REBOOT_CMD_KEXEC
115 .RB ( RB_KEXEC ,
116 0x45584543, since Linux 2.6.13).
117 Execute a kernel that has been loaded earlier with
118 .BR kexec_load (2).
119 This option is available only if the kernel was configured with
120 .BR CONFIG_KEXEC .
121 .TP
122 .B LINUX_REBOOT_CMD_POWER_OFF
123 .RB ( RB_POWER_OFF ,
124 0x4321fedc; since Linux 2.1.30).
125 The message "Power down." is printed, the system is stopped,
126 and all power is removed from the system, if possible.
127 If not preceded by a
128 .BR sync (2),
129 data will be lost.
130 .TP
131 .B LINUX_REBOOT_CMD_RESTART
132 .RB ( RB_AUTOBOOT ,
133 0x1234567).
134 The message "Restarting system." is printed, and a default
135 restart is performed immediately.
136 If not preceded by a
137 .BR sync (2),
138 data will be lost.
139 .TP
140 .B LINUX_REBOOT_CMD_RESTART2
141 (0xa1b2c3d4; since Linux 2.1.30).
142 The message "Restarting system with command \(aq%s\(aq" is printed,
143 and a restart (using the command string given in
144 .IR arg )
145 is performed immediately.
146 If not preceded by a
147 .BR sync (2),
148 data will be lost.
149 .TP
150 .BR LINUX_REBOOT_CMD_SW_SUSPEND
151 .RB ( RB_SW_SUSPEND ,
152 0xd000fce1; since Linux 2.5.18).
153 The system is suspended (hibernated) to disk.
154 This option is available only if the kernel was configured with
155 .BR CONFIG_HIBERNATION .
156 .PP
157 Only the superuser may call
158 .BR reboot ().
159 .PP
160 The precise effect of the above actions depends on the architecture.
161 For the i386 architecture, the additional argument does not do
162 anything at present (2.1.122), but the type of reboot can be
163 determined by kernel command-line arguments ("reboot=...") to be
164 either warm or cold, and either hard or through the BIOS.
165 .\"
166 .SS Behavior inside PID namespaces
167 .\" commit cf3f89214ef6a33fad60856bc5ffd7bb2fc4709b
168 .\" see also commit 923c7538236564c46ee80c253a416705321f13e3
169 Since Linux 3.4,
170 if
171 .BR reboot ()
172 is called
173 from a PID namespace other than the initial PID namespace
174 with one of the
175 .I cmd
176 values listed below,
177 it performs a "reboot" of that namespace:
178 the "init" process of the PID namespace is immediately terminated,
179 with the effects described in
180 .BR pid_namespaces (7).
181 .PP
182 The values that can be supplied in
183 .I cmd
184 when calling
185 .BR reboot ()
186 in this case are as follows:
187 .TP
188 .BR LINUX_REBOOT_CMD_RESTART ", " LINUX_REBOOT_CMD_RESTART2
189 The "init" process is terminated,
190 and
191 .BR wait (2)
192 in the parent process reports that the child was killed with a
193 .B SIGHUP
194 signal.
195 .TP
196 .BR LINUX_REBOOT_CMD_POWER_OFF ", " LINUX_REBOOT_CMD_HALT
197 The "init" process is terminated,
198 and
199 .BR wait (2)
200 in the parent process reports that the child was killed with a
201 .B SIGINT
202 signal.
203 .PP
204 For the other
205 .I cmd
206 values,
207 .BR reboot ()
208 returns \-1 and
209 .I errno
210 is set to
211 .BR EINVAL .
212 .SH RETURN VALUE
213 For the values of
214 .I cmd
215 that stop or restart the system,
216 a successful call to
217 .BR reboot ()
218 does not return.
219 For the other
220 .I cmd
221 values, zero is returned on success.
222 In all cases, \-1 is returned on failure, and
223 .I errno
224 is set appropriately.
225 .SH ERRORS
226 .TP
227 .B EFAULT
228 Problem with getting user-space data under
229 .BR LINUX_REBOOT_CMD_RESTART2 .
230 .TP
231 .B EINVAL
232 Bad magic numbers or \fIcmd\fP.
233 .TP
234 .B EPERM
235 The calling process has insufficient privilege to call
236 .BR reboot ();
237 the caller must have the
238 .B CAP_SYS_BOOT
239 inside its user namespace.
240 .SH CONFORMING TO
241 .BR reboot ()
242 is Linux-specific,
243 and should not be used in programs intended to be portable.
244 .SH SEE ALSO
245 .BR systemctl (1),
246 .BR systemd (1),
247 .BR kexec_load (2),
248 .BR sync (2),
249 .BR bootparam (7),
250 .BR capabilities (7),
251 .BR ctrlaltdel (8),
252 .BR halt (8),
253 .BR shutdown (8)