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?

pomsky
  • 68,507
jk_
  • 1,839
  • 2
  • 12
  • 5
  • 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 '14 at 01:09
  • 2
    No, it freezes after login (mostly), usually after undocking. – jk_ Apr 27 '14 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 '14 at 12:41
  • If you use any shell-extensions from: https://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 '14 at 15:20
  • 1
    I tried to deactivate all of them, still having the problem :( – jk_ May 05 '14 at 08:24
  • Then I don't know! Sorry!! – v2r May 05 '14 at 16:33
  • I prefer: gnome-shell -r & Works great from gnome-terminal in the same display. – wieczorek1990 Oct 13 '14 at 13:35
  • I finally defined an alias, which should work from any shell, in tty or other: alias gnomeshellrestart='echo "gnome-shell --replace -d" $(w| grep "$USER"| awk "{print \$3}"|grep ":"|head -1)| at now' – MoreIT Oct 04 '17 at 14:29
  • I've had this problem since at least 10 years on Linux and Gnome, on several different computers. Both on Debian and Ubuntu. Once every month you login and after that everything is frozen except the mouse pointer and you can't do anything and nothing useful in any log file :/ – BjornW Apr 23 '19 at 10:43

11 Answers11

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.

wjandrea
  • 14,236
  • 4
  • 48
  • 98
Braiam
  • 67,791
  • 32
  • 179
  • 269
  • 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 '15 at 08:24
  • @Chriki yeah, it was sigquit, through most signals would make gnome-shell process end. – Braiam Apr 29 '15 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 '17 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 '17 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 07 '20 at 05:38
  • @fsevenm none of these touch the shell configuration. Maybe gnome gets smart and says "well, I got terminated uncleanly, maybe I should blame one of these extensions, mmm" – Braiam Feb 07 '20 at 21:53
  • You are GOD! very very Thank you!! – 井上智文 Jun 09 '21 at 09:40
  • Using Ubuntu 20 this saved my session I would suggest using CTRL+ALT+F3 or to get into any TTY session console for the "killall -3 gnome-shell". Did not kill my other open apps. – Lelouch Lamprouge Aug 21 '21 at 17:22
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.
Braiam
  • 67,791
  • 32
  • 179
  • 269
korc
  • 634
  • I created a shell function that sets the DBUS_SESSION_BUS_ADDRESS from the gnome-shell process environment (so you can logout otheruser1 otheruser2) http://askubuntu.com/a/874504/17941 – sehe Jan 21 '17 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 09 '17 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 '19 at 15:50
  • Thank you for this! – seanbreeden Oct 19 '20 at 21:26
  • This is very useful for writing shell extensions – 0x777C Oct 10 '22 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!

Gerhard Stein
  • 699
  • 7
  • 8
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.

pomsky
  • 68,507
masina
  • 141
  • 1
    Simple, and works like a charm! (At least for me) – Katai May 10 '18 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 '19 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.

fitojb
  • 2,188
Jay Aurabind
  • 344
  • 2
  • 12
  • 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 '14 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 ? – Jay Aurabind Apr 25 '14 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 '14 at 09: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. – Jay Aurabind Apr 26 '14 at 09: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 '14 at 12:38
  • "Ended up with this trick" : Shall I concur that it perfectly solves your problem ? – Jay Aurabind Apr 30 '14 at 05:13
  • Actually, not. It sometimes restarts the gnome-shell properly, but today it did not helped. After undocking, my gnome-shell froze, restart de-froze the shell, but I was not able to turn on the wifi :( Still my only option is service gdm restart. – jk_ May 01 '14 at 13:30
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
  • 28,662
landas
  • 114
  • 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) – Steeve McCauley Aug 04 '14 at 13:37
  • great it works for me...! you save my day. appreciated. – NomanJaved May 18 '18 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.
wjandrea
  • 14,236
  • 4
  • 48
  • 98
  • 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 01 '19 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.

DanglingPointer
  • 1,123
  • 1
  • 13
  • 23
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.

  • "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 '23 at 09:40
  • 1
    On Wayland, Gnome can't restart. You have to either use Xorg or reboot. – Wrichik Basu Apr 25 '23 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.

karel
  • 114,770
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
  • 197,895
  • 55
  • 485
  • 740
Walter
  • 11
  • 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 '16 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? – TSJNachos117 Oct 10 '17 at 15:42