What can I do when Ubuntu freezes?

Although Ubuntu/Linux is much more stable than Windows, it happens sometimes that the Ubuntu screen freezes, that you can't control your computer with your mouse/keyboard, what is usually the sign that the system is in a unstable state. If so, I propose you the following procedure.

Step 1: 
Check-up whether the problem is a single application

Sometimes a single application stops responding, but the system still works fine. So the first step is to verify whether the problem is a single application. When a application window stops responding, you can usually stop it by clicking the X close button at the top left of the window. That will generally result in a dialog box saying that the program is not responding and presenting you with the option to kill the program, what might solve your problem. If you can't close a window by these normal means, you can hit Alt + F2, type xkill, and hit enter. Your mouse cursor will then turn into an X. Hover over the offending window and left-click to kill it. If your program is running from a terminal, you can usually stop it with Ctrl + C.

Ubuntu xkill command
Step 2: 
Check-up whether the problem is the keyboard or mouse

Sometimes only the keyboard or mouse stop working. This means, that you can re-boot Ubuntu with the device that is still working. With the keyboard by hitting "Ctrl" + "Alt" + "Del" and then selecting "Restart" With the mouse by choosing "Shutdown" from the menu bar and then selecting "Restart"

Ubuntu restart
Step 3: 
Restart with REISUB

The SysRq Key lets you send some low level commands independent of the system state. This means that if the system is frozen you can use these key combinations to perform certain actions and thus regain control. If your system locks completely, you can REISUB it, which is a safer alternative to the "cold rebooting" of the computer. While holding Alt AND the SysRq (Print Screen) keys, type R E I S U B. R: Switch to XLATE mode E: Send Terminate signal to all processes except for init I: Send Kill signal to all processes except for init S: Sync all mounted filesystems U: Remount filesystems as read-only B: Reboot

SysRq Key