184

Sometimes, my GNOME Shell freezes. I can see (hear) background processes working (playing music), but I can't do anything in GNOME. No Alt+F2 followed by R and Enter.

I can switch to console using: Ctrl+Alt+F1, login as the same user and execute:

gnome-shell --replace

and return back Ctrl+F7, but then, I get a strange behavior. For example I cannot edit network connections. I cannot logout as well. What is the proper way to restart the gnome-shell?

pomsky
  • 70,557
jk_
  • 1,949

11 Answers11

266

The easier way is just pressing Alt + F2, type r then Enter. This will work so long the shell is usable.

You can also send SIGQUIT to the gnome-shell process which will terminate only the shell:

killall -3 gnome-shell

Other methods use more destructive means, which close all the applications, this shouldn't.

wjandrea
  • 14,504
Braiam
  • 69,112
48
  • If you want to ask "nicely" to gnome-shell to restart itsself, then you can call it's internal restart function over dbus with following command (assuming you have DBUS_SESSION_BUS_ADDRESS env var set to the correct value and run as same user):

    dbus-send --type=method_call --print-reply --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval string:'global.reexec_self()'
    
  • If you want to run a new instance, gnome-shell --replace should do fine. On console you need to define necessary environment variables like DISPLAY, DBUS* and so on. Refer to /proc/$gnome_shell_pid/environ

  • If you want to restart existing one, then killall -HUP gnome-shell will do it. If you do that too often though, gnome-shell might disable all extensions, forcefully log you off or otherwise behave in non-userfriendly manner.
Braiam
  • 69,112
korc
  • 636
  • 5
  • 3
16

If you have installed ubuntu gnome, which you should have, you might be using the gnome display manager. In that case you should change to another TTY, like Ctrl + Alt + F4 and then

sudo service gdm restart

I also wrote an article about such situation recently:

Help, my Linux Desktop hangs!

Best Luck!

13

Here is a different workaround:

  1. Log in a local terminal by pressing CTRL+ALT+F1.
  2. Run the command:

    sudo kill -HUP $(pidof gnome-shell)
    
  3. Return to the graphical interface by pressing CTRL+ALT+F7.

PS: I'm using lightdm instead of gdm3.

pomsky
  • 70,557
masina
  • 131
6

Since you are not satisfied with gnome-shell --replace, you might want to try restarting the display manager itself.

sudo service lightdm restart

I think that will kill other processes you are running. Also refer http://worldofgnome.org/how-to-restart-gnome-shell-when-freezes-if-ever/

If you are seriously into something that make you freeze everytime, enable the SysRq as mentioned in https://www.kernel.org/doc/Documentation/admin-guide/sysrq.rst, and then give <alt><sysrq/print_screen_key><k> to kill whatever its there on the screen.

fitojb
  • 2,233
4

I do sometimes have the same problem as you describe, and my solution is:

Ctrl + Alt + F1, login as same user and execute:

sudo pkill -9 ^gnome-shell

And return back with Ctrl + Alt + F7

If this is the proper way, I don't know. For me it works everytime.

don.joey
  • 29,392
landas
  • 114
4

Restart X

  • First find which display manager your Ubuntu is using with following command:

    cat /etc/X11/default-display-manager
    

    in my case it's /usr/sbin/gdm3

    From Inside X or OUTSIDE X

  • For Method 1 to 4, find out which display you're using by using the w command.

    w
    

    the answer may be for example tty3, (therefor my (ack's) "return to my display" key is Ctrl+Alt+F3

Methods

  1. Ctrl+Alt+F1 to exit, and Ctrl+Alt+F3 to bring one back
  2. sudo /etc/init.d/gdm3 restart
  3. systemctl restart gdm.service
  4. sudo service gdm3 restart
  5. dbus-send --type=method_call --print-reply --dest=org.gnome.Shell /org/gnome/Shell org.gnome.Shell.Eval string:'global.reexec_self()'
  6. An easy way is just pressing Alt + F2, and type r then press Enter. This will work so long the shell isn't unusable.
wjandrea
  • 14,504
2

For Ubuntu 20.04 if you have ssh enabled on the affected computer.

  1. ssh into the affected computer from a remote computer
  2. execute killall -1 gnome-shell without sudo.

There's a bit of lag at the start when logging as it is re-instantiating all gnome objects be patient; but most if not all running programs should continue working.

2

The (currently) most upvoted answer by @Braiam misses some details. Some of the other answers didn't work for me. Hence, I am writing what did work for me. Note that this is tested on Ubuntu 20.04 running GNOME Shell 3.36.9.

  1. If the current instance of GNOME Shell is still responsive, restart it with Alt + F2rEnter. This should work in most cases. But once in a while, the shell may become completely unresponsive, or even this command may get stuck. In that case, go on to the following steps.

  2. Go to a TTY. On my system, the key combination would be Ctrl + Alt + F3 to F6.

  3. Log in. (Note that in TTY, number keys on numeric keypad may not work!)

  4. Find the PID of GNOME Shell using pidof gnome-shell.

  5. Kill it using sudo kill -1 <pid> replacing <pid> with the output of the above step. (If you don't use sudo, you will get the Operation not permitted error.)

  6. Re-execute step 3. If nothing is returned, then GNOME Shell has not yet restarted. Keep repeating step 3 until you get the PID of the new instance of the shell. (Note that this PID will not be the same as what you had got in step 3.)

  7. Once the PID of the new shell instance is returned, you can safely return to the GUI. Type exit and log out of the TTY.

  8. Return to the GUI. In Ubuntu 20.04, this is achieved using Ctrl + Alt + F2.

This method did not close any of the applications that were running. Unsaved changes in such applications still existed without any problem. All GNOME extensions were loaded properly too.

1
  1. Press Ctrl+Alt+F2 to switch to a terminal window. Sometimes, this is not possible.

  2. Press Alt+SysRq+R to get the keyboard.

  3. If pressing Ctrl+Alt+F2 before failed, try it again now.

  4. Press Alt+SysRq+E to terminate all processes.

  5. Press Alt+SysRq+I to kill all processes.

  6. Press Alt+SysRq+S to sync your disks.

  7. Wait for OK or Done message. If you don't see a message, look at your HDD light to see if Sync made a difference.

  8. Press Alt+SysRq+U to unmount all disk drives.

  9. Wait for OK or Done message. If you don't see a message in 15-30 seconds, assume disks are unmounted (or that an unmount is not possible) and proceed.

  10. Press Alt+SysRq+B to reboot.

karel
  • 122,292
  • 133
  • 301
  • 332
0

kill -15 gnome-shell does not work for me but kill -9 does. I think it is because kill -9 triggers a segfault which triggers gnome-shell to restart itself, while kill -15 does not.

muru
  • 207,228
Walter
  • 11