0

There are a lot of questions and answers about restarting Plasma 5. I realize that using KRunner is the best option, but today I could not access KRunner and had to use a terminal.

After reading Difference between nohup, disown and &, I felt like these two topics (restarting Plasma 5 and nohub/disown/background jobs) need to be combined into one answer specific to restarting KDE Plasma 5 the right way. Almost every answer I have seen about restarting Plasma 5 ignores the issue of nohup.

By following different answers about restarting Plasma 5, I have, at various times, found myself unable to close a terminal window without killing my newly started Plasma 5 session.

The following script is from a few answers, mostly https://unix.stackexchange.com/a/499373, and is modified to include nohup. Is this the definitive, comprehensive solution? Or is it a mess that needs to be avoided?

#!/bin/sh
kbuildsycoca5 # rebuilds the plasmashell database
timeout 5 kquitapp5 plasmashell #without timeout, it can hang for ~30-60 seconds
pgrep -U $USER -x plasmashell &>/dev/null && pkill -U $USER -x plasmashell
pgrep -U $USER -x plasmashell &>/dev/null && pkill -U $USER -x -9 plasmashell # here the process does not get to clean-up.
killall -9 plasmashell #sends a signal to all processes running any of the specified commands
pgrep -U $USER -x plasmashell &>/dev/null && echo "ERROR: cannot kill plasmashell"
nohup plasmashell &

My specific question is about the last line:

nohup plasmashell &

Is that correct in this context?

9
  • Not a nix veteran or something but it is my regular way to run anything from the terminal. Sep 26, 2021 at 1:21
  • @AbdullahIbnFulan - thanks, but I'm hoping for an answer specific to plasmashell
    – MountainX
    Sep 26, 2021 at 1:47
  • No, nohup is not the way to do anything sensible for a lot of reasons that have been rehashed ad-nauseam. Better try with setsid >/dev/null 2>&1 </dev/null your_command ... and be sure that systemd-logind is not configured to KillUserProcesses=yes
    – user313992
    Sep 26, 2021 at 8:49
  • Of course, you can change >/dev/null to >/some/file if you want to capture the output of your_command.
    – user313992
    Sep 26, 2021 at 8:57
  • @MountainX yes, including killall plasmashell && nohup plasmashell >/dev/null & Sep 26, 2021 at 13:08

1 Answer 1

0

Restarting kde apps as in the comments is the wrong way.

I have a script which I call if I wish to restart things such as plasmashell...

#!/bin/sh
for i in $* do
        kquitapp5 ${i}
        PID=$(ps -ax | grep ${i}$ | awk '{print $1}'
        test -n ${PID} && kill -9 ${PID}
        kstart5 ${i}
done
11
  • Thanks for your answer. However, as discussed in various posts on restarting Plasma5, this method will not always work. Yesterday, for example, this method did not work for me. I could have rebooted, or used some version of kill -9 as in the OP. There may be other options, but this is not one of them in those circumstances.
    – MountainX
    Sep 26, 2021 at 16:22
  • If you kill -9, then it should restart automatically. If not, then just run kstart5 plasmashell. You can add it to the script. It does work.
    – Bib
    Sep 26, 2021 at 16:25
  • You can add it to the script. That's a low effort reply. There are already a lot of answers on other questions similar to this. My question seeks a more definitive solution (call it a canonical answer), particularly in regard to handling the harder cases and avoiding side effects.
    – MountainX
    Sep 26, 2021 at 17:13
  • Satisfied now ?
    – Bib
    Sep 26, 2021 at 17:31
  • thank you for editing your answer. It's not a bad answer now. However, this question has come up a lot in the past and I was specifically trying to avoid a rehash. After reading many prior answers, I remain unclear in regard to what is really the best answer. You have not provided convincing information that your answer really is better than any others. If I do not hold answers to this question to that higher standard, this question will simply devolve into a duplicate of all the others on this topic.
    – MountainX
    Sep 26, 2021 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .