How to restart the display manager
If X is hung, you should be able rejigger it by restarting the display manager. In 11.10, it's lightdm, recent past versions use gdm. Change the following examples as appropriate for your version. You can restart it a few different ways. I prefer the simplicity of the restart
:
sudo restart gdm
Or you can use the service
command:
sudo service gdm restart
Init script hackers stuck on sysv will prefer invoke-rc.d
:
sudo invoke-rc.d gdm restart
If it's really hung..
If restarting the display manager doesn't work, pull out a hammer and kill it dead with one or both of these commands:
sudo pkill -9 X
sudo pkill -9 gdm
Which example should I use? Does it matter?
Use the first one. restart
is a link to initctl
, which is Upstart, which is Ubuntu's init manager that they are trying to convert everything over to.
The other two commands, service
and invoke-rc.d
are there only to control the old-style SysV init scripts. SysV exists in modern Ubuntu only for backwards compatibility. Don't rely on it. But if you must..
service
is for end-users. It returns a simple exit code. If you're a normal user needing to control a SysV style init script, use this tool.
invoke-rc.d
is for init script hackers. It returns a bunch of varied and useful exit codes. There's no reason a normal user should use this tool. There isn't any harm for normal users, it's just more complicated.
Best Answer
TTY really is an instance of virtual terminal. Early computers were just giant boxes, to which a real, physical terminal was connected and are generally called TTY (short for teletype). Virtual terminals are called virtual for that exact reason - your computer is now one single unit, and you have couple different virtual software teletypes (more specifically, for Ubuntu it's 6 ttys, but you can spawn more. See my answer here: https://askubuntu.com/a/817859/295286). Within TTY you can run processes, be it a text-based shell like
bash
or graphical server within which runs a graphical shell.What happens precisely is that you have specific instance of GUI running ( or in more technical terms, you have X11 server running ) in a particular tty. In case of Ubuntu, it defaults to TTY #7. When I was using Fedora 21, that defaults to TTY1. And you can have multiple instances of GUI, see this for example: Start another GUI on different TTY
So effectivelly, GUI session is nothing more than a separate process running within a TTY.
Additional info: