I would like to do that using the command-line, because sometimes my computer freezes and I need to force a shutdown (I know it's not good to the hardware). And: What is the difference between Halt and Shutdown commands?
If you can still access a text mode console, or if you can log in remotely:
- You can use
psor other process listing tools and kill to try killing some processes. A few programs will save your work (at least to a recovery file) if they receive a
kill -HUPor plain
kill. They might not have time to do it if you go straight for rebooting.
sudo killfollowed by a process ID to kill a process that's running as root or some other user who is not you.
rebootto reboot (e.g.
sudo rebootif you use
sudoto gain administrative access). Run
haltto power the computer off. Both of these call
shutdownwith appropriate options.
If absolutely everything is hosed, but you have console access, you can use magic SysRq to at least flush all file changes to disk unmount filesystems cleanly. Press
- Alt+SysRq+E to send SIGTERM to all processes (optional).
- Alt+SysRq+S to synchronize (flush) filesystem changes to disk.
- Alt+SysRq+U to forcefully unmount (actually, remount read-only) all filesystems.
- Alt+SysRq+B to reboot.
(Note: you'll sometimes see “REISUB”, but the R and I steps are useless.)
If it is a frozen X session, hit ctrl+alt+f1 to get to a console. Log in and from there, execute
/sbin/shutdown -r now. Depending on permissions, you may need to prefix these commands with
sudo or first
su to become root.
You may also be able to kill the offending process. Run
ps aux to list all processes and look for ones which are using a lot of CPU and/or memory (third and fourth columns). Use
kill <pid>, where pid is the number in the second column of the
ps output). If this doesn't kill the process, you may need to run
kill -9 <pid> to forcefully kill it.
If your BIOS is setup in a way where you have to press the power-button more than X seconds to actually turn off the machine, press the power-button once. This will give the acpi-signal for shutdown/halt/poweroff.