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?
plasmashell
– MountainX Sep 26 '21 at 01:47setsid >/dev/null 2>&1 </dev/null your_command ...
and be sure that systemd-logind is not configured toKillUserProcesses=yes
– Sep 26 '21 at 08:49>/dev/null
to>/some/file
if you want to capture the output ofyour_command
. – Sep 26 '21 at 08:57killall plasmashell && nohup plasmashell >/dev/null &
– Abdullah Ibn Fulan Sep 26 '21 at 13:08plasmashell
terminates because of aSIGHUP
signal and not because of any other reason,nohup ... &
is not reliable because it's racy and the background process could be killed bySIGHUP
before being able to ignore the signal or exec its command. That will happen in 99% of cases where thenohup ... &
is the last line. Since you can do the very same thingnohup
does, but without the race with just(trap '' HUP; your_command ... &)
there's exactly 0 reason to ever usenohup
from a script. – Sep 27 '21 at 08:13nohup
as a kind of talisman, supposed to bring good luck to a process and shy away the spirits that may kill it along its journey. Millions of people doing that can't be wrong. – Sep 27 '21 at 08:21