if shutting down computer from GUI is the same as from terminal with command:
It depends on the GUI, of course, but most of the time a DBus message is sent, either to init directly or to something like ConsoleKit / systemd-logind.
While both methods eventually result in telling init to start the shutdown process, they mainly differ in what kind of authorization they use, e.g. shutdown via systemd-logind can be initiated by anyone logged in at the console, while the shutdown
command is usually root-only.
(The same does not apply to systemctl poweroff
, though, which goes through a more GUI-like mechanism than shutdown
.)
Does init process receive any signal like SIGPWR or SIGTERM or it shuts down differently? Hope you can help. Thanks.
It depends on the init system, of course, but most of the time an IPC message is sent, either via D-Bus, a plain Unix socket, or a named pipe.
systemd has D-Bus and /run/systemd/private
as fallback;
Upstart has D-Bus and apparently /run/initctl
as well;
SysV init has /dev/initctl
, sometimes /etc/.initctl
, recently /run/initctl
.
(SIGPWR has a different meaning – it merely informs init that there was a power failure, without explicitly requesting any action.)
Assuming your distro is still using
– LawrenceC – 2016-05-05T11:01:42.710init
(many usesystemd
now),init
receives a command via a socket it is listening on (which can be sent usingpoweroff
ortelinit
command) to switch to run level 0 or 6. This makesinit
run the 'K' teardown scripts from the current level and then run the 'S' setup scripts for the desired level - but on run level 0 or 6, the final script run shuts down the system or reboots instead of starting X. The actual command that reboots or shuts off ishalt
I think (http://linux.die.net/man/8/halt). PID 1 which would beinit
ignores SIGTERM.