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.

  • 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 (linux.die.net/man/8/halt). PID 1 which would be init ignores SIGTERM. – LawrenceC May 5 '16 at 11:01
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.)

  • 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 May 5 '16 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.