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
setsid >/dev/null 2>&1 </dev/null your_command ...
and be sure that systemd-logind is not configured toKillUserProcesses=yes
>/dev/null
to>/some/file
if you want to capture the output ofyour_command
.killall plasmashell && nohup plasmashell >/dev/null &