How to Restart X Server in Ubuntu 12.04 Without Rebooting

How to Restart X Server in Ubuntu 12.04 Without Rebooting

Three reliable methods to restart the X server in Ubuntu 12.04 Precise Pangolin — LightDM service restart, TTY console switching, and killing the X process — with guidance on when each is appropriate.

Tested on: Ubuntu 12.04 LTS

There are moments when the Ubuntu desktop stops responding — a frozen window manager, a corrupted display after a driver update, or a graphics test that locked the framebuffer. Your instinct is to hold the power button, but a full reboot is almost never necessary. Restarting only the X server kills the graphical session, re-reads the Xorg configuration, and drops you back to a fresh login screen in seconds. This guide covers three methods, ranked from cleanest to most aggressive, all tested on Ubuntu 12.04 Precise Pangolin.

Ubuntu 12.04 LightDM login screen

Background: What Is the X Server?

The X server (Xorg) is the process that manages your display hardware, draws windows, and handles keyboard and mouse input. In Ubuntu 12.04 the display stack looks like this:

Hardware → Kernel (DRM/KMS) → Xorg → Window Manager (Compiz/Metacity) → Applications

When Xorg is restarted, everything above it in the stack — the window manager, panels, and all graphical applications — is terminated and restarted from scratch. The kernel, networking, background daemons, and any active TTY sessions are unaffected.

Ubuntu 12.04 uses LightDM as the display manager. LightDM is responsible for starting Xorg, presenting the login greeter, and launching your desktop session after authentication. All three restart methods ultimately cycle LightDM.

Before You Begin: Save Your Work

Every method below will kill all graphical applications without warning. There is no graceful shutdown prompt. Before proceeding:

  1. Save open documents in every application.
  2. Commit or stash any uncommitted code in your editor.
  3. Close any active file transfers.
  4. Note any terminal commands you will need to re-run — your terminal history survives, but running processes do not.

Step-by-Step Methods

Method 1: Restart LightDM (Cleanest)

This is the recommended approach. It gracefully stops the display manager, terminates Xorg, and starts a fresh instance.

If you can still open a terminal (Ctrl+Alt+T):

sudo service lightdm restart

The screen will go black for one to three seconds, then the LightDM greeter reappears. Log back in normally.

If the GUI is frozen but the keyboard still works:

Switch to a virtual console with Ctrl+Alt+F1. You will see a text-mode login prompt. Log in with your username and password, then run:

sudo service lightdm restart

Switch back to the graphical console with Ctrl+Alt+F7 (or F8 on some configurations). The fresh LightDM greeter will be waiting.

Method 2: Stop and Start LightDM Separately

Splitting the operation into two commands gives you a window to perform maintenance between killing the old session and starting the new one — useful for editing xorg.conf or swapping driver packages.

sudo service lightdm stop

At this point there is no graphical display. You are working in a pure text console. Do whatever maintenance you need:

# Example: reconfigure the NVIDIA driver
sudo dpkg-reconfigure nvidia-current

When ready, bring the graphical session back:

sudo service lightdm start

Terminal showing lightdm restart commands

Method 3: Kill the X Process Directly (Most Aggressive)

This is the brute-force option. Use it only when LightDM’s init scripts are themselves hung or when the service command is unresponsive.

First, find the Xorg process:

ps aux | grep Xorg

You will see output like:

root  1234  5.2  1.8  248360  72312 tty7  Ss+  10:03  2:14 /usr/bin/Xorg :0 ...

Kill it:

sudo kill -9 1234

Replace 1234 with the actual PID from the ps output. LightDM will detect that its child Xorg process has died and automatically respawn a new instance. You will be returned to the login screen within seconds.

If LightDM itself is unresponsive and does not respawn Xorg:

sudo kill -9 $(pgrep lightdm)
sudo service lightdm start

Method 4 (Bonus): Re-enable Ctrl+Alt+Backspace

Ubuntu disabled the “Zap” key combination starting with 9.04. To restore it on 12.04:

sudo dpkg-reconfigure keyboard-configuration

Walk through the prompts (accept defaults for keyboard model, layout, and variant). When asked “Use Ctrl+Alt+Backspace to terminate the X server?”, select Yes.

Alternatively, add the option directly to your Xorg configuration:

sudo mkdir -p /etc/X11/xorg.conf.d
sudo tee /etc/X11/xorg.conf.d/10-zap.conf <<'EOF'
Section "InputClass"
    Identifier "Enable Zap"
    MatchIsKeyboard "on"
    Option "XkbOptions" "terminate:ctrl_alt_bksp"
EndSection
EOF

After a logout/login cycle (or an X restart using one of the methods above), pressing Ctrl+Alt+Backspace will immediately kill Xorg and return you to the LightDM greeter.

What Happens to Running Applications

When X is restarted, the following occurs:

ComponentEffect
GUI applicationsTerminated immediately (SIGKILL)
Unsaved documentsLost unless the application has autosave
Clipboard contentsLost
Terminal sessions (GUI)Terminated
tmux/screen sessionsSurvive — reattach after login
SSH connectionsUnaffected
Background daemonsUnaffected (cron, sshd, apache, etc.)
Network connectionsRemain active
Mounted filesystemsRemain mounted

The single most effective precaution is to run long-lived terminal work inside tmux or screen. These sessions are attached to a pseudo-terminal, not to Xorg, and will survive any X restart unscathed:

tmux new -s work

After restarting X and logging back in:

tmux attach -t work

Diagram showing which processes survive an X restart

When to Use Each Method

ScenarioRecommended Method
Desktop is slow but responsiveMethod 1 — sudo service lightdm restart
GUI is frozen, keyboard worksMethod 1 via TTY (Ctrl+Alt+F1)
Need to edit Xorg config between stop and startMethod 2 — stop, edit, start
LightDM itself is hungMethod 3 — kill Xorg PID
Frequent need to restart X during developmentMethod 4 — Ctrl+Alt+Backspace

Common Pitfalls

  1. Forgetting to save before restarting X. This is the number one cause of data loss during X restarts. Every graphical application is killed without a shutdown prompt. Make saving your reflex before touching any restart command.
  2. Switching to the wrong TTY after restart. After restarting LightDM from TTY1, the graphical session may appear on tty7 or tty8 depending on your configuration. If Ctrl+Alt+F7 shows a blank screen, try F8.
  3. Running sudo service lightdm restart inside a GUI terminal. This works, but the terminal itself will be killed mid-command. You may see an error flash before the screen resets. This is cosmetic — the restart completes regardless.
  4. Editing /etc/X11/xorg.conf with syntax errors. If Xorg cannot parse its configuration file it will fail to start, leaving you at a text console. Always keep a backup:
    sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bak
    
  5. Assuming startx is a valid restart method. Running startx from a TTY launches a second X session on a new display (:1). It does not restart the existing session. Use the service lightdm commands instead.
  6. Killing all Xorg instances on a multi-seat system. If your machine serves multiple displays, killall Xorg will terminate every seat. Target the specific PID with kill -9 <PID> instead.

Verifying the Restart

After logging back in, confirm that the X server is running a fresh instance:

ps aux | grep Xorg
cat /var/log/Xorg.0.log | head -5

The log file timestamp should match the current time, confirming a new Xorg session was started. Check for error lines:

grep '(EE)' /var/log/Xorg.0.log

Any lines prefixed with (EE) indicate errors — typically missing modules or misconfigured options — that should be resolved before the problem recurs.

Frequently Asked Questions

Will restarting X close all my running applications?
Yes. Every method described in this article terminates the X server process, which immediately closes all graphical applications. Save all work before proceeding.
Is there a keyboard shortcut to restart X in Ubuntu 12.04?
The Ctrl+Alt+Backspace shortcut is disabled by default in 12.04. You can re-enable it with ‘sudo dpkg-reconfigure keyboard-configuration’ and selecting ‘Yes’ when asked about the Zap key sequence.
What is the difference between restarting X and rebooting?
Restarting X only kills the display server and the graphical session. The kernel, background services, network connections, and any running TTY sessions remain untouched. A reboot restarts the entire operating system.
Does this work on Ubuntu 12.04 with NVIDIA proprietary drivers?
Yes. The NVIDIA driver re-initialises when the X server starts again. If you are troubleshooting a driver issue, check /var/log/Xorg.0.log after the restart for error messages.
Can I restart X remotely via SSH?
Yes. SSH sessions run independently of the X server. You can restart LightDM over SSH with ‘sudo service lightdm restart’. The SSH session will remain connected while the local graphical session resets.