How many ways do you know to switch Linux off?

This is a question I love to ask during interviews:

How many ways do you know to switch off a linux system?

The point of this question is to see how somebody will think. Will the candidate only think about command line options, or will he suggest dirty/creative/violent ways as well? There are of course no good or bad answer, I am more interested in seeing the candidate think.

The GUI way

Click on the menu or equivalent, then switch off.

Using ACPI

Press the power button. On systems that support it, this should send a switchoff signal to cleanly switch off the system.

The clean command line way

shutdown and halt, poweroff, reboot: the last 3 are the same command, actually symlinked to /sbin/reboot

# does not power off the machine at the end
halt
# same as halt but actually powers off if supported
poweroff
# reboot
reboot
# same as above, but allows for delay and warning
shutdown

Using Magic SysRq keys

As wikipedia says, they are key combinations understood by the Linux kernel, which allows the user to perform various low-level commands regardless of the system’s state. Two of them allow to shutdown (o) or reboot (b) the system.

The dirty command line way

Most ACPI or magic key commands can be issued command line, by playing with /proc or /sys.

Killing init (kill -9 1) does not work since a while as it is ignored by the kernel. You can kill all processes though, with the special pid -1:

# does not work
kill -9 1
# Works
kill -9 -1

Being very dirty

Take the power plug off.

For desktops and laptops, long press the power button.

I am sure there are others ways I do not know about, I would love to hear about them.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s