I would like to implement a keyboard shortcut to restart gnome-shell whenever this one crashes (some bugs aren't currently fixed just yet). For this I would need a command line to restart the shell.
The Alt+F2 and restart command won't work when the shell is crashed because the prompt is implemented in the shell.
Hence, how to restart the gnome-shell from command line?
110 Answers
GNOME Shell 3.30.1 on Ubuntu 18.10
The command to replace gnome-shell would be sending a SIGQUIT signal to it with:
killall -3 gnome-shellor:
killall -SIGQUIT gnome-shellAs of GNOME Shell 3.30.1 on Ubuntu 18.10, the solution below no longer works, and will kick the user to the login screen, losing all of their work.
Before GNOME Shell 3.30.1
The command to replace gnome-shell would be:
gnome-shell --replace &The ampersand is added to return the shell prompt after running the command; pressing Ctrl+C or closing the terminal instead would make the desktop unusable, and require a full restart.
From the manual page of gnome-shell:
-r, --replace Replace the running window manager
Unsure which version you are using?
The command to check your GNOME Shell version is:
gnome-shell --version 9 The easiest way is to Alt+F2 and type r then ↵.
Since GNOME Shell 3.30.1: You can also do a killall -3 gnome-shell.
In case the whole gnome-shell got frozen there is a way how to restart it from the terminal without restarting the whole X window:
- Ctrl+Alt+F2 to switch to terminal
- log in with your credentials (username and password) and then run:
DISPLAY=:0 gnome-shell -r &- log out
exitand - Alt+F1 to switch back to graphical interface X Window.
Before GNOME Shell 3.30.1 the command should just be gnome-shell --replace.
The Gnome 40 the equivalent of Alt+F2 restart is:
busctl --user call org.gnome.Shell /org/gnome/Shell org.gnome.Shell Eval s 'Meta.restart("Restarting…")'Got this tip myself from .
2I came up with this function to logout users (see at the bottom)
It assumes
- you have sudo permissions
- you have bash
- the users have 1 running X session (although you should be able to issue the same logout command multiple times to get rid of remaining sessions)
You can give it multiple usernames:
logout john jane mike elisaAnd you can give it additional options:
logout john --forceSo, I have the following helper function:
function forcelogout() { logout "$@" --no-prompt --force
}Notes:
- This is a blunt instruments and works by just copying the entire session environment. This could be more selective.
- Sometimes logout seems to take a while
- In rare occasions the session keeps being reported until someone visits the vt where the session ran, but nothing is there anymore)
CODE
function logout() { local USERNAME export USERNAMES=( ) while [ -n "$1" ]; do case "$1" in -* ) break ;; *) USERNAMES+=( "$1" ); shift ;; esac; done for USERNAME in "${USERNAMES[@]}"; do local SESSION_PID=$(pgrep -fu "$USERNAME" gnome-session|head -1) if [ -n "$SESSION_PID" ]; then ( sudo -u "$USERNAME" cat "/proc/$SESSION_PID/environ" | xargs -0 -n 1 echo export echo "gnome-session-quit --logout $@" ) | sudo -u "$USERNAME" sh -; fi done
} 3 I defined an alias:alias gnomeshellrestart='echo "gnome-shell --replace -d" $(w| grep "$USER"| awk "{print \$3}"|grep ":"|head -1)| at now'
You may be able to start a terminal by right-clicking with the mouse on background and type there (alt-tab is dysfct then, too), if not, login to a tty with e.g. ctrl-alt-F2 and run from there.
In order to proper restart all related, I prefer restarts of whole stack (if tty1..4 works)
sudo killall -9 gdm
sudo killall -9 gdm3
sudo killall -9 lightdm Sending TERM signal to Gnome Shell 42.1 works for me on Ubuntu 22.04:
pkill -TERM gnome-shellNote: TERM is the default signal for pkill.