Kill xserver from command line (init 3/5 does not work)
Matthew Martinez
I'm running Linux Mint 10, although I've had this same issue with other variants of Linux. I've been told/found while researching that if the X server hangs or otherwise errors, one can drop to a root prompt, usually at another tty, and execute init 3 (to drop to single user mode) and then init 5 to return to the default, graphical session.
Needless to say, I've tried this before in multiple configurations on multiple machines to no avail. The only feedback I receive form executing those two commands is a listing of VMWare services (from a kernel module) that are stopped and then restarted.
Note: If I run startx (either before or after init 3), then I am told that the xserver is still running and that I should remove /tmp/.X0-lock. Having tried that, it removes that error message, but claims that the xserver cannot be attached as another instance is running.
How do I kill the xserver completely? Can I killall some process name?
3 Answers
Linux Mint is based on Debian. In Debian, the single user run level is 1; 3 is still a multi-user run level and as such allows X to continue execution. So, you need to switch to run level 1, init 1, to stop all processes initiated by the default run level (2). Then you can re-init to the proper run level: init 2.
See Debian run levels for more information.
1The easiest way to kill your X server is to press Ctrl+Alt+Backspace.
For example, on Ubuntu, the keyboard shortcut is called "DontZap", and can be re-enabled by following these instructions. It should be the same on Linux Mint.
It's best not to run startx. It is independent from init 3/init 5, and will confuse things.
These days, pkill is preferred over killall. It basically does the same thing, but it has a partner command pgrep you can use to see what it would kill before doing it.
So try pgrep X or pgrep Xorg, and then run pkill X or pkill Xorg if pgrep lists only programs you want to kill.
On my Ubuntu system, the most reliable command I can find is:
pgrep -f '^/usr/bin/X 'which means you can kill all X servers using
pkill -f '^/usr/bin/X '(but I haven't tested it).
Finally, don't forget to have a look in /var/log/X.0.log and ~/.xsession-errors. Maybe you can figure out what is causing the X server hangs.
When I update Xorg or video drivers:
- Press Ctrl+Alt+F1
- Log in as a user
Type the following commands:
sudo /etc/init.d/lightdm stop #or slim gdm mdm etc... #do stuff sudo /etc/init.d/lightdm start #or slim gdm mdm etc...
(Stopping the Display Manager also stops X.)