I had a device running Ubuntu 12.04 LTS have its screen freeze. Generally I have simply jumped onto an available tty, i.e. Ctrl-Alt-F1 and executed the command
/etc/init.d/lightdm restart or
service lightdm restart. This however kills everything I have open. How do I avoid this?
Now I got it for Unity (I just replaced my GNOME shell with unity without logging out or closing windows):
This only works if not the X-Server or GNOME is frozen but only Unity or the GNOME-Shell.
How it works: The communication between programs and the X-Server for displaying their UI is working over a network socket. This normally is at "localhost:0" short ":0". By setting the DISPLAY variable, the programs know where to find the X-Server to communicate with it, so programs are displayed on the X-Server on tty7 even if the program is running on tty1.
The content of windows is managed by the X-Server whereas the position and borders of the windows is managed by the window manager integrated in unity or the GNOM-shell so there is a way to replace only them without restarting the applications on the X-Server.
PS: I'm just describing what I understand it to be, so please edit and correct me if I'm wrong in some points.
For the GNOME-Shell, there is another way to restart it. After changing to tty simply type in