[systemd-devel] systemd reboot problem

Lennart Poettering lennart at poettering.net
Thu Mar 30 08:47:38 UTC 2017


On Tue, 07.03.17 03:15, lin webber (webberlin at outlook.com) wrote:

> I use “system("reboot")” in my C program and system does not shutdown.I think that systemd is waiting for some services to shutdown which can't shutdown immediately.
> But I don't want to wait for those services to shutdown.How can I shutdown my system immediately in my C program.which API should I call?
> Thank you for reply.

There are several ways to reboot your system:

1) use the raw reboot() syscall. In this case file systems might end
   up being dirty, and some more complex daemons might not like it
   either.

2) Use "systemctl reboot -ff", which is pretty much the same as #1,
   but accessible from the shell.

3) Use "systemctl reboot -f", which is a slightly friendlier version
   than the above. In this mode, systemd won't bother with stopping
   services correctly (instead it will just SIGTERM them all and
   SIGKILL what is left then). However it will still place all file
   systems in a clean state before issuing reboot().

4) Use "systemctl reboot", which is the friendliest version and
   correctly shuts down all services, i.e. is equivalent to plain
   "reboot" the way you already tried.


Unless you have a completely stateless system with all file systems
either read-only or formatted on each boot #3 is the vastly better
option than #1/#2.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list