Home » Questions » Computers [ Ask a new question ]

How to shutdown a computer instantly (1 to 5 secs) without using a physical switch/socket?

How to shutdown a computer instantly (1 to 5 secs) without using a physical switch/socket?

Is there any command / program via which I may shutdown my system instantly (1 to 5 secs)?

Asked by: Guest | Views: 283
Total answers/comments: 5
Guest [Entry]

sudo shutdown -h now
Guest [Entry]

"You can power off the machine immediately without syncing disks by writing ""o"" to /proc/sysrq-trigger as root, or as any user with write permissions on that file.

As a shell script it would look something like

#!/bin/sh
echo o >/proc/sysrq-trigger

There is a sysctl option about sysrq, but option only affects triggering by keyboard.

If you would like to restart immediately instead of powering off, you can send ""b"" instead of ""o""; but keep in mind that while sysrq-trigger is the fastest way to shut down, there may be faster ways to restart. Board firmware (BIOS/UEFI) can take a lot of time to reinitialize hardware, so it is usually faster to use kexec to effect the restart, because the hardware remains initialized.

As you probably know, this is not recommended in any case where you have a filesystem that is mounted as writable, even if you don't think you've written anything important to that filesystem while it was mounted. Even if you do not care about the integrity of data on that filesystem, shutting down or restarting like this can make booting up slower.

Make sure that none of your persistent filesystems are mounted as writable."
Guest [Entry]

"Taken from another SE site:

Alt + SysRq + B is instant reboot, and Alt + SysRq + O is instant shutdown.

Reference: Here"
Guest [Entry]

"I used this small script to turn off the system. Actually it's used this for a prank on a ""prototyping"" machine: ""Hey dude, let's see what that awesome .sh do!""

#!/bin/bash
echo 1 > /proc/sys/kernel/sysrq-trigger; #enables sysrq triggers
echo u > /proc/sysrq-trigger # remount the system as ready only
#edited# echo s > /proc/sysrq-trigger # sync all write-pending data to disk
sync
echo o > /proc/sysrq-trigger # shut off the system power.

(This script imitates the same as hitting Alt + SysRq + u/s/o as previously explained.)
Of course i't cause an abnormal system termination (mysql tables, etc may crash), so use only on dummy machines.
Note: Sync may take some time. I've seen that if the system has a lot of free memory (for cache) and you copy a bunch of files to a pen drive, sync-ing takes more time, but I recommend it even for a prank.

Edit:
It's better to use sync instead of writing 's' to sysrq-trigger:
writing 's' will not block the script execution, so after requesting cache to be written into disk, the machine will shut off immediately. In contrast with sync command, sync will return after the writing process get done. So the script execution will be blocked, until the cache flushing get done."
Guest [Entry]

Hold the power key for about 4 seconds, it's quite fast.