12

Is there a way to restart GNOME Shell other than by using Alt + F2, R + Enter?

With respect to the question, I have gone through Difference between `gnome-shell --replace` and r in Alt+F2, but I didn't get what I was looking for.

I am looking for a command which exactly does what Alt + F2, r + Enter do.

Please note that I am not willing to do the gnome-shell -- replace command...

I did check both the things Alt + F2,r Enter and gnome-shell --replace...
There is a lot of difference, I found...

Eliah Kagan
  • 117,780
PRATAP
  • 22,460

4 Answers4

5

The command for doing this is (Tested in Ubuntu 20.04 Only)

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval 'Meta.restart(_("Restarting…"))'

enter image description here

PRATAP
  • 22,460
3

As Diego F. Rodríguez V. mentioned, there is no way to access that from a terminal. However,

killall -3 gnome-shell

is very close and keeps your active session in tact. It sends a QUIT signal (SIGQUIT), and since gnome-shell is set to start automatically whenever X is up, it technically does a similar thing.

kill -SIGQUIT PID
kill -3 PID
kill -QUIT PID

can be done as well, but it requires a PID (process ID) as an argument, which can be found via

ps x | grep "gnome-shell"
1

I also wanted to restart gnome shell programmatically because it seems there is some kind of memory leak in Ubuntu 19.10. gnome-shell starts consuming a little over 200 MB but after several hours of use it can reach more than 900 MB.

alt+f2,r,enter solves the problem gracefully. A small "restarting" message shows up. The change is almost unnoticeable, all windows maintain their position and running programs keep their state. Only the desktop background seems to flicker while it reloads.

When using gnome-shell --replace some programs are killed with all the work in them lost, the windows that survive may change their position and several parts of the screen appear to be redrawn. I also tried killall gnome-shell with similar results.

Unfortunately I don't think there is a way to access this functionality from the command line as it is embedded deep in the gnome-shell code for the RunDialog GObject:

gnome-shell > js > ui > runDialog.js [37]

this._internalCommands = {
    'lg': () => Main.createLookingGlass().open(),
    'r': this._restart.bind(this),
    ...
  • 1
    I read this article about the memory leak in gnome-shell but I guess the fix hasn't made it yet into Ubuntu: https://feaneron.com/2018/04/20/the-infamous-gnome-shell-memory-leak/ – Diego F. Rodríguez V. Mar 13 '20 at 03:57
0

What worked best for me is to invoke the call from the Cinnamon source code. Works on 5.4.10. Also does not prompt for fallback mode.

dbus-send --type=method_call --dest=org.Cinnamon /org/Cinnamon org.Cinnamon.Eval string:"global.real_restart()"
Gab
  • 101