173

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?

9
  • Does gnome-shell freezes while using the search-function in gnome-shell overview, or on what particular occasion, if you can tell?
    – v2r
    Apr 26, 2014 at 1:09
  • 2
    No, it freezes after login (mostly), usually after undocking.
    – jk_
    Apr 27, 2014 at 18:10
  • 2
    So far, I didn't found a working solution. In the end, I end up with this workaround.
    – jk_
    Apr 29, 2014 at 12:41
  • If you use any shell-extensions from: extensions.gnome.org deactivate all of them and reboot, to see if one of them caused the trouble. I use an older version of gnome-shell and had plenty of issues due to that exact cause! (Maybe it is just as simple as that?!)
    – v2r
    Apr 30, 2014 at 15:20
  • 1
    I tried to deactivate all of them, still having the problem :(
    – jk_
    May 5, 2014 at 8:24

11 Answers 11

250

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.

8
  • 6
    +1 for the SIGHUP tip, however, wouldn’t the correct command then be killall -1 gnome-shell? At least according to man 7 signal, the value for SIGHUP is 1. Value 3 corresponds to SIGQUIT. I have sent value 1 to the Gnome Shell and it was cleanly restarted as expected.
    – Chriki
    Apr 29, 2015 at 8:24
  • @Chriki yeah, it was sigquit, through most signals would make gnome-shell process end.
    – Braiam
    Apr 29, 2015 at 13:31
  • 3
    I tried this on Fedora 25 and killall -3 gnome-shell resulted in killing all applications for me.
    – comfreak
    May 26, 2017 at 16:08
  • 9
    I wish we could also use a terminal command having exactly the same effect as Alt+F2 and r, i.e. without blanking the whole screen...
    – Sadi
    Jun 11, 2017 at 14:04
  • This one disabled all my gnome-shell-extensions. Even after restart, they didn't back until I activated them again one by one.
    – fsevenm
    Feb 7, 2020 at 5:38
47
  • 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.
5
  • I created a shell function that sets the DBUS_SESSION_BUS_ADDRESS from the gnome-shell process environment (so you can logout otheruser1 otheruser2) askubuntu.com/a/874504/17941
    – sehe
    Jan 21, 2017 at 13:25
  • 4
    Got the error Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.Shell was not provided by any .service files without sudo and Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11 with sudo.
    – Seanny123
    Nov 9, 2017 at 16:24
  • What if there is no gnome-shell running (i.e. it died)? how would one get DISPLAY and other vars
    – Dan M.
    Dec 20, 2019 at 15:50
  • Thank you for this! Oct 19, 2020 at 21:26
  • This is very useful for writing shell extensions
    – 0x777C
    Oct 10, 2022 at 19:40
15

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!

4
  • 10
    be careful, I did it on the same TTY and this kill my current session.. Oct 24, 2018 at 12:51
  • this completely fucked up the current session: it started to blink and then went to nirvana.. had to reboot.
    – Nik O'Lai
    Oct 11, 2019 at 18:11
  • It depends on the version of Ubuntu you are using. Here it was 16.04 Jul 14, 2022 at 9:02
  • I agree, be careful! This command cause you can lost settings. For me: lost mouse settings, disabled GNOME Shell Extensions (extensions: Dash to Panel, Clock Override, Datetime Format).
    – mkczyk
    Jan 27, 2023 at 15:40
14

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.

2
  • 1
    Simple, and works like a charm! (At least for me)
    – Katai
    May 10, 2018 at 12:51
  • 2
    Whilst this does successfully restart gnome-shell; I find that some programs - presumably those less well integrated with GNOME - don't survive; eg: Firefox, Thunderbird, VirtualBox VMs. Example of programs that survive: "Files", Terminal, ImageViewer. Ideally there's be a way to restart gnome-shell without jeopardizing any running program (Ubuntu 19.10)
    – sxc731
    Nov 20, 2019 at 10:28
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.

7
  • 3
    Restarting lighdm works, but I want to avoid it, because I have to reopen everything from a scratch. Especially if I know it is problem of a Gnome-shell and restarting it almost works.
    – jk_
    Apr 25, 2014 at 17:29
  • I am unaware of other methods to restrat just the gnome shell. Did you try whether DISPLAY=:7 gnome-shell --replace works ? Apr 25, 2014 at 17:43
  • 1
    No, it does not, I use display, when w shows display different than :0. If I use a wrong display I get an error.
    – jk_
    Apr 26, 2014 at 9:07
  • Sorry, I'm out of options. You should probably ask in the gnome user/developer mailing list. First figure out why you have abnormalities with alt-f2-r or gnome-shell --replace when it is the gnome's recommended way. Apr 26, 2014 at 9:45
  • So am I. I did even followed this link setting up more ENV variables, but I still cannot edit network connections when restarting gnome-shell from a different terminal. In the end, I end up with this trick
    – jk_
    Apr 29, 2014 at 12:38
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.

2
  • 4
    This will kill all users instances of gnome-shell which may not be something you want to do in a multi-user scenario. Normally you only have to kill your own (pkill -HUP gnome-shell) Aug 4, 2014 at 13:37
  • great it works for me...! you save my day. appreciated.
    – NomanJaved
    May 18, 2018 at 19:13
3

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.
1
  • Method 5 is lifted verbatim from korc's answer and 6 from Braiam's answer. Plagiarism isn't against the rules here, but it's definitely not cool. All you really need to do is indicate that the work is not your own by putting it in quotes, and give attribution by including a link to the source post and a link to the author's profile page. For more details, see this blog post: Attribution Required
    – wjandrea
    Sep 1, 2019 at 18:31
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.

2
  • "Re-execute step 3. If nothing is returned, then GNOME Shell has not yet restarted": No matter how long I wait no GNOME shell restarts. Ubuntu 22.04, GNOME Shell 42.5, Wayland.
    – JonBrave
    Apr 24, 2023 at 9:40
  • 1
    On Wayland, Gnome can't restart. You have to either use Xorg or reboot. Apr 25, 2023 at 10:11
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.

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.

2
  • 3
    kill -9 doesn't trigger a segfault. It sends SIGKILL, an uncatchable signal for which the only action is to quit immediately. It should only be used when the application doesn't respond to SIGTERM, which is 15.
    – muru
    Jan 17, 2016 at 21:28
  • pkill -11 gnome-shell would trigger a segfault, since that's literally what signal 11 does. BTW, kill needs a process ID, NOT a process name. Did you mean pkill or killall? Oct 10, 2017 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .