Linux: shutdown from GUI vs from terminal

0

Hello I'm new with Linux and could not figure out if shutting down computer from GUI is the same as from terminal with command:

shutdown -P now

P.S When shutting down, Does init process receive any signal like SIGPWR or SIGTERM or it shuts down differently? Hope you can help. Thanks.

user590536

Posted 2016-05-05T10:48:39.353

Reputation: 71

Assuming your distro is still using init (many use systemd now), init receives a command via a socket it is listening on (which can be sent using poweroff or telinit command) to switch to run level 0 or 6. This makes init 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 is halt I think (http://linux.die.net/man/8/halt). PID 1 which would be init ignores SIGTERM.

– LawrenceC – 2016-05-05T11:01:42.710

Answers

1

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.)

user1686

Posted 2016-05-05T10:48:39.353

Reputation: 283 655

Thank you very much for the answer. Could you please answer one more? I'm creating simple program and lauching init process as different user. What would be easiest way to shut it down? – user590536 – 2016-05-05T12:44:27.850