52

In 12.04 How do you kill the X server from the command line and from the GUI interface and how do you start it from the virtual terminal?

Jorge Castro
  • 71,754
Robert
  • 653

6 Answers6

42

One way to restart an instance of the X server is to run (from the commandline)

sudo service lightdm restart

For Ubuntu 15.04 and later:

sudo systemctl restart lightdm.service

and for Kubuntu 15.04 and later:

sudo systemctl stop sddm.service
Carolus
  • 587
labarna
  • 2,614
  • 2
  • 22
  • 32
  • 1
    lightdm? I thought gdm was for GNOME, kdm for KDE, xdm for XFCE and lightdm for LXDE! and to stp it from the gUI? – Robert May 03 '12 at 22:26
  • 2
    lightdm is the default for 12.04, I'm not sure when it was made the default perhaps in 11.10? – labarna May 03 '12 at 23:50
  • 1
    restarting lightdm doesn't kill Xorg. Only an instance of it. – Jack Mayerz May 05 '13 at 00:23
  • 2
    lightdm starts only one instance of Xorg, so restarting lightdm should close the only open Xorg instance, unless you're doing something much more complicated. – labarna May 06 '13 at 13:05
21

On 12.04, you can restart the server with the shortcut keys: Right Alt + Print Screen + K.

Mike Haas
  • 796
  • 1
    What a strange combination!. Print??. It has no logic; and what would "(Right alt) + (Print Screen) + K" be in an Apple keyboard? I have right command and no print – Robert May 03 '12 at 22:30
  • 1
    http://en.wikipedia.org/wiki/Magic_SysRq_key has more info on it if you want to understand the logic behind it. printscreen is the same key as sysrq(System Request). – semi Jul 11 '12 at 23:43
  • @semi: "printscreen is the same key as sysrq" - not on my keyboard. sysreq is the same key as delete. – Nathan Osman May 04 '13 at 23:28
  • What happens if you hit right alt + sysrq + k on your key layout? Does it still work? I just know internally they always call it the magic sysrq key, so it seems odd that it would become the magic printscreen key just because of another layout being used. – semi May 06 '13 at 23:13
  • 4
    Nothing happens on my machine (fresh install of 13.10). – ajdev8 Nov 14 '13 at 01:11
  • 1
    In order for this to work you need to run this command once: sudo echo kernel.sysrq=1 > /etc/sysctl.d/10-magic-sysrq.conf – Naveen May 30 '15 at 11:39
  • With the netbook I just tried it on, I needed to use the left Alt rather than the right (which is Alt Gr). – mwfearnley Jan 27 '16 at 14:04
13

In Ubuntu 14.04:

Press Ctrl+Alt+F1 and then run:

sudo service gdm stop

or

sudo service lightdm stop

… depending on your display manager.

NOTE: To recover use startx, alternatively replace the stop with start in either of the above commands.

dessert
  • 39,982
bhass1
  • 386
8

Kill : xkill -a. -a means it will kill all display instances. For more information run man xkill.

Run : xinit. Also startx but this command is to start an instance and not the server itself. For more information run man xint and man startx.

I don't believe it's possible to kill Xserver from GUI, and even if it were, it would not be the right way to do it.

Jack Mayerz
  • 1,669
  • Wouldn't that kill all individual windows, which is not what the user wants? For example I don't want to kill all my firefox windows, I want to restart the visualisation. – isomorphismes Aug 23 '13 at 01:47
  • 4
    The user said: "kill and start the X server". That seems to be exactly what he wants. It's not about restarting gnome-shell. – Gui Ambros Jun 26 '14 at 01:16
  • Doesn't work for me from tty: Unable to open display "" – xeruf Mar 01 '21 at 10:43
  • This is more generalized than restarting lightdm services in case you don't have a display manager. UPVOTE! – T. Zack Crawford Mar 17 '21 at 22:58
0

On Ubuntu 22.04 (and a few previous versions) you can add a hotkey to your gnome session to kill the x server. Install gnome-tweaks via sudo apt install gnome-tweaks and then open it (logo button and then "tweaks" and enter) then goto "Keyboard & Mouse" -> "Additional Layout Options" -> "Key sequence to kill the X server" -> "Ctrl+Alt+Backspace"

Grifball
  • 101
0

On more recent versions of Ubuntu (e.g. 22.04) which use Gnome and systemd, you can use:

$ sudo systemctl restart gdm.service
Adam
  • 1