man-pages/man2/reboot.2.html
2021-03-31 01:06:50 +01:00

383 lines
8.8 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of REBOOT</TITLE>
</HEAD><BODY>
<H1>REBOOT</H1>
Section: Linux Programmer's Manual (2)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
reboot - reboot or enable/disable Ctrl-Alt-Del
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
/* Since kernel version 2.1.30 there are symbolic names LINUX_REBOOT_*
<BR>&nbsp;&nbsp;&nbsp;for&nbsp;the&nbsp;constants&nbsp;and&nbsp;a&nbsp;fourth&nbsp;argument&nbsp;to&nbsp;the&nbsp;call:&nbsp;*/
<P>
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<BR>
<B>#include &lt;<A HREF="file:///usr/include/linux/reboot.h">linux/reboot.h</A>&gt;</B>
<P>
<B>int reboot(int </B><I>magic</I><B>, int </B><I>magic2</I><B>, int </B><I>cmd</I><B>, void *</B><I>arg</I><B>);</B>
<P>
/* Under glibc and most alternative libc's (including uclibc, dietlibc,
<BR>&nbsp;&nbsp;&nbsp;musl&nbsp;and&nbsp;a&nbsp;few&nbsp;others),&nbsp;some&nbsp;of&nbsp;the&nbsp;constants&nbsp;involved&nbsp;have&nbsp;gotten
<BR>&nbsp;&nbsp;&nbsp;symbolic&nbsp;names&nbsp;RB_*,&nbsp;and&nbsp;the&nbsp;library&nbsp;call&nbsp;is&nbsp;a&nbsp;1-argument
<BR>&nbsp;&nbsp;&nbsp;wrapper&nbsp;around&nbsp;the&nbsp;system&nbsp;call:&nbsp;*/
<P>
<B>#include &lt;<A HREF="file:///usr/include/unistd.h">unistd.h</A>&gt;</B>
<BR>
<B>#include &lt;<A HREF="file:///usr/include/sys/reboot.h">sys/reboot.h</A>&gt;</B>
<P>
<B>int reboot(int </B><I>cmd</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>reboot</B>()
call reboots the system, or enables/disables the reboot keystroke
(abbreviated CAD, since the default is Ctrl-Alt-Delete;
it can be changed using
<B><A HREF="/cgi-bin/man/man2html?1+loadkeys">loadkeys</A></B>(1)).
<P>
This system call fails (with the error
<B>EINVAL</B>)
unless
<I>magic</I>
equals
<B>LINUX_REBOOT_MAGIC1</B>
(that is, 0xfee1dead) and
<I>magic2</I>
equals
<B>LINUX_REBOOT_MAGIC2</B>
(that is, 672274793).
However, since 2.1.17 also
<B>LINUX_REBOOT_MAGIC2A</B>
(that is, 85072278)
and since 2.1.97 also
<B>LINUX_REBOOT_MAGIC2B</B>
(that is, 369367448)
and since 2.5.71 also
<B>LINUX_REBOOT_MAGIC2C</B>
(that is, 537993216)
are permitted as values for
<I>magic2</I>.
(The hexadecimal values of these constants are meaningful.)
<P>
The
<I>cmd</I>
argument can have the following values:
<DL COMPACT>
<DT id="1"><B>LINUX_REBOOT_CMD_CAD_OFF</B>
<DD>
(<B>RB_DISABLE_CAD</B>,
0).
CAD is disabled.
This means that the CAD keystroke will cause a
<B>SIGINT</B>
signal to be
sent to init (process 1), whereupon this process may decide upon a
proper action (maybe: kill all processes, sync, reboot).
<DT id="2"><B>LINUX_REBOOT_CMD_CAD_ON</B>
<DD>
(<B>RB_ENABLE_CAD</B>,
0x89abcdef).
CAD is enabled.
This means that the CAD keystroke will immediately cause
the action associated with
<B>LINUX_REBOOT_CMD_RESTART</B>.
<DT id="3"><B>LINUX_REBOOT_CMD_HALT</B>
<DD>
(<B>RB_HALT_SYSTEM</B>,
0xcdef0123; since Linux 1.1.76).
The message &quot;System halted.&quot; is printed, and the system is halted.
Control is given to the ROM monitor, if there is one.
If not preceded by a
<B><A HREF="/cgi-bin/man/man2html?2+sync">sync</A></B>(2),
data will be lost.
<DT id="4"><B>LINUX_REBOOT_CMD_KEXEC</B>
<DD>
(<B>RB_KEXEC</B>,
0x45584543, since Linux 2.6.13).
Execute a kernel that has been loaded earlier with
<B><A HREF="/cgi-bin/man/man2html?2+kexec_load">kexec_load</A></B>(2).
This option is available only if the kernel was configured with
<B>CONFIG_KEXEC</B>.
<DT id="5"><B>LINUX_REBOOT_CMD_POWER_OFF</B>
<DD>
(<B>RB_POWER_OFF</B>,
0x4321fedc; since Linux 2.1.30).
The message &quot;Power down.&quot; is printed, the system is stopped,
and all power is removed from the system, if possible.
If not preceded by a
<B><A HREF="/cgi-bin/man/man2html?2+sync">sync</A></B>(2),
data will be lost.
<DT id="6"><B>LINUX_REBOOT_CMD_RESTART</B>
<DD>
(<B>RB_AUTOBOOT</B>,
0x1234567).
The message &quot;Restarting system.&quot; is printed, and a default
restart is performed immediately.
If not preceded by a
<B><A HREF="/cgi-bin/man/man2html?2+sync">sync</A></B>(2),
data will be lost.
<DT id="7"><B>LINUX_REBOOT_CMD_RESTART2</B>
<DD>
(0xa1b2c3d4; since Linux 2.1.30).
The message &quot;Restarting system with command '%s'&quot; is printed,
and a restart (using the command string given in
<I>arg</I>)
is performed immediately.
If not preceded by a
<B><A HREF="/cgi-bin/man/man2html?2+sync">sync</A></B>(2),
data will be lost.
<DT id="8"><B>LINUX_REBOOT_CMD_SW_SUSPEND</B>
<DD>
(<B>RB_SW_SUSPEND</B>,
0xd000fce1; since Linux 2.5.18).
The system is suspended (hibernated) to disk.
This option is available only if the kernel was configured with
<B>CONFIG_HIBERNATION</B>.
</DL>
<P>
Only the superuser may call
<B>reboot</B>().
<P>
The precise effect of the above actions depends on the architecture.
For the i386 architecture, the additional argument does not do
anything at present (2.1.122), but the type of reboot can be
determined by kernel command-line arguments (&quot;reboot=...&quot;) to be
either warm or cold, and either hard or through the BIOS.
<A NAME="lbAE">&nbsp;</A>
<H3>Behavior inside PID namespaces</H3>
Since Linux 3.4,
if
<B>reboot</B>()
is called
from a PID namespace other than the initial PID namespace
with one of the
<I>cmd</I>
values listed below,
it performs a &quot;reboot&quot; of that namespace:
the &quot;init&quot; process of the PID namespace is immediately terminated,
with the effects described in
<B><A HREF="/cgi-bin/man/man2html?7+pid_namespaces">pid_namespaces</A></B>(7).
<P>
The values that can be supplied in
<I>cmd</I>
when calling
<B>reboot</B>()
in this case are as follows:
<DL COMPACT>
<DT id="9"><B>LINUX_REBOOT_CMD_RESTART</B>, <B>LINUX_REBOOT_CMD_RESTART2</B>
<DD>
The &quot;init&quot; process is terminated,
and
<B><A HREF="/cgi-bin/man/man2html?2+wait">wait</A></B>(2)
in the parent process reports that the child was killed with a
<B>SIGHUP</B>
signal.
<DT id="10"><B>LINUX_REBOOT_CMD_POWER_OFF</B>, <B>LINUX_REBOOT_CMD_HALT</B>
<DD>
The &quot;init&quot; process is terminated,
and
<B><A HREF="/cgi-bin/man/man2html?2+wait">wait</A></B>(2)
in the parent process reports that the child was killed with a
<B>SIGINT</B>
signal.
</DL>
<P>
For the other
<I>cmd</I>
values,
<B>reboot</B>()
returns -1 and
<I>errno</I>
is set to
<B>EINVAL</B>.
<A NAME="lbAF">&nbsp;</A>
<H2>RETURN VALUE</H2>
For the values of
<I>cmd</I>
that stop or restart the system,
a successful call to
<B>reboot</B>()
does not return.
For the other
<I>cmd</I>
values, zero is returned on success.
In all cases, -1 is returned on failure, and
<I>errno</I>
is set appropriately.
<A NAME="lbAG">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="11"><B>EFAULT</B>
<DD>
Problem with getting user-space data under
<B>LINUX_REBOOT_CMD_RESTART2</B>.
<DT id="12"><B>EINVAL</B>
<DD>
Bad magic numbers or <I>cmd</I>.
<DT id="13"><B>EPERM</B>
<DD>
The calling process has insufficient privilege to call
<B>reboot</B>();
the caller must have the
<B>CAP_SYS_BOOT</B>
inside its user namespace.
</DL>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
<B>reboot</B>()
is Linux-specific,
and should not be used in programs intended to be portable.
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+systemctl">systemctl</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?1+systemd">systemd</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?2+kexec_load">kexec_load</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+sync">sync</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?7+bootparam">bootparam</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?7+capabilities">capabilities</A></B>(7),
<B><A HREF="/cgi-bin/man/man2html?8+ctrlaltdel">ctrlaltdel</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+halt">halt</A></B>(8),
<B><A HREF="/cgi-bin/man/man2html?8+shutdown">shutdown</A></B>(8)
<A NAME="lbAJ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="14"><A HREF="#lbAB">NAME</A><DD>
<DT id="15"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="16"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DL>
<DT id="17"><A HREF="#lbAE">Behavior inside PID namespaces</A><DD>
</DL>
<DT id="18"><A HREF="#lbAF">RETURN VALUE</A><DD>
<DT id="19"><A HREF="#lbAG">ERRORS</A><DD>
<DT id="20"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="21"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="22"><A HREF="#lbAJ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:34 GMT, March 31, 2021
</BODY>
</HTML>