If your GUI ubuntu desktop is not freezed, open a terminal by Ctrl+Alt+T shortcut and do the following:
To shutdown now :
sudo shutdown -P now
To restart now :
sudo shutdown -P -r now
To shutdown after (say) 20 minutes :
sudo shutdown -P 20
Similarly, for restart also replace now
by 20
.
(To stop timed execution: Say after 15 minutes you decide not needed to shutdown/restart then go to the terminal window in which you executed the command and press Ctrl+C.)
If your GUI ubuntu desktop is freezed, go to commandline ubuntu desktop by Ctrl+Alt+F1(Here in place of F1, the keys F1to F6 are applicable ; also Ctrl+Alt+F7 will give you the GUI desktop back). Now in commandline ubuntu enter your login username and password. After successful login execute the same commands described above for shutdown (or restart).