2

I want to shutdown computer with my phone using KDE Connect. That can be easily done by adding a shutdown command in the setting of the Runcommand plugin within the KDE Connect program in Linux.

enter image description here

The idea is to close the applications gracefully without abruptly killing them and losing last configurations, for example.

I know about systemctl poweroff.

I read under this question that "shutdown -h now or shutdown -r now are graceful", and also that scripts involved may vary depending on the distribution. What is the situation in Ubuntu?

Are the commands above preferable to systemctl poweroff for my purpose?

5
  • Related (but perhaps outdated): What is the proper terminal-way to shutdown?
    – Melebius
    Jan 23, 2019 at 12:53
  • @Melebius - the title is similar but that question is not mentioning the "graceful" or "friendly" aspect. Anyway, I will edit my title to make it KDE-Connect-specific (I don't want sudo etc).
    – user47206
    Jan 23, 2019 at 13:07
  • 1
    I suppose (but don’t know) every single one of the different shutdown commands kills the processes equally gracefully by sending SIGTERM – that’s kill’s default signal and widely considered to be The Right Thing™ to do. Most importantly, every reasonable software saves its data and only then exits when receiving this signal.
    – dessert
    Jan 23, 2019 at 13:26
  • 1
    Oh, run file $(which shutdown) to see what shutdown in fact is. ;) Well, I suppose there’s not really a difference…
    – dessert
    Jan 23, 2019 at 13:37
  • qdbus org.kde.ksmserver /KSMServer logout 0 2 0 is what you want. This is from superuser.com/a/396091.
    – jamadagni
    Feb 3, 2019 at 3:27

1 Answer 1

0

A graceful shutdown means that the programs receive a hang up signal (HUP). If the program is developed properly, it will listen to this signal and act accordingly (prepare the program to get shut down, clearing used memory, deleting tmp files, etc.).

It does not really matter, if it is done on the GUI or on the terminal, the HUP signal will be send either way.

This also answers your question if Ubuntu behaves differently then other distros. It does not. The mechanism is the same. An odd behaviour can be expected from programs which don't act properly when they get a HUP signal, but this is because the program does not do it properly, it has nothing to do with the distro.

P.S.:

shutdown -h 

will power off the system, while

shutdown -r

will reboot the system (so this is unusable for you)

Just use shutdown or add -P or --poweroff (but this is the default anyway according to the man page).

8
  • P.S.S.: this is totally different to reboot, which sends the KILL signal instead of HUP, hence the system just kills everything and reboots the system. Tr5y for yourself and do a time measurement of reboot and shutdown -r 0
    – s1mmel
    Jan 23, 2019 at 14:10
  • could you add a few info on why systemctl poweroff is also used/usable? is systemctl adding something to the procedure?
    – user47206
    Jan 23, 2019 at 14:38
  • 1
    see systemctl as a "wrapper". systemctl is a command line tool from systemd and systemd is (not only but also) responsible for starting and stopping service. But in the end, systemd also sends a HUP signal.
    – s1mmel
    Jan 23, 2019 at 15:49
  • 1
    According to man shutdown, shutdown -h is “[e]quivalent to --poweroff, unless --halt is specified”, while shutdown -H halts the machine!
    – dessert
    Jan 23, 2019 at 16:46
  • 2
    @s1mmel - considering the man page: I see no -p argument, it's -P, --poweroff or -h. While "halt" is -H, not -h, as per dessert's comment.
    – user47206
    Jan 23, 2019 at 17:36

You must log in to answer this question.