How to Kill and Restart X Server

A GUI is a very complex piece of software and there could be any number of reasons why it would lock up on you. If you need to kill your x server and then restart it, here are some tips:
Killing X server via Terminal
Open a Terminal (ex: gnome-terminal) and type:
# init 3
That will kill the x server and throw you into runlevel 3 mode (all text). If it doesn’t find the command, then switch to the root user by typing “su -” (you will need to know the root password).
Restarting X server
If you need to restart the X server, and you’re in GUI mode, simply use the keyboard combination CTRL+ALT+BACKSPACE. For the most part, it’ll work.
Working with a Console
If the previous keyboard combination did not work then try CTRL+ALT+F1. This will not kill X server, it will simply open a full screen console. I believe Red Hat and Fedora Core have F1-F6 as options. If you want to switch back to a GUI environment use the keyboard combination CTRL+ALT+F7.
Processes
Once you’re in the full screen console mode, you will have to use the kill command to close X server. Unfortunately; you can’t simply type in “kill xserver”. You’ll have to find it’s process ID, using the ps command. The ps command displays a list of the current processes running on the machine. There are tons of options for this command, use man ps to find which option works for your situation.
Once you found the process ID for the process you want to end, type in kill {process_id}. Let’s assume your process id is 1344. You will type kill 1344 and presto that process is no longer functioning.
Init Command
If you want to get out of the full screen console and into a bonafied console environment, use the init command.
- init 3 – kills all processes and loads the user into a full console.
- init 5 – runs the multi-user and GUI scripts in rc.d/rc5, which will start your login manager and put you back into a GUI environment.
Starting X server
Once you have X server killed, or no longer running – you can either type in init 5 or startx to get X server up and running again. If all else fails, simply reboot.
How I Came Up with This Tip
I ran into this issue when I installed a free copy of GTA 2 (Grand Theft Auto 2) from Rockstar Games [slash] classics. I was informed about that link from The Linux Link Tech Show podcast. I had no problems installing the game but I am having issues after the game starts. It seems to resize my desktop to roughly a 640×480 resolution. I haven’t figured it out yet. I did a search on www.google.com/linux and found a PDF document from Whil Hentzen (PDF – 349KB) and it did a great job of explaining a couple different methods of killing X server. I encourage everyone to save a copy of Whil’s whitepaper on your hard drive.
Pingback: Diarios de programacion