I guess the behaviour depends on the system installed and the settings you choose. On my Xubuntu distro (xfce4), I seem to remember you could set this in the system settings. Probably works the same in other Linux distros.
When/if the machine freezes and you need to switch it off "by force", you can press and hold the power button for a few seconds.