Shut down the computer!

Challenge:

In the programming language of your choice, shut down the machine that your code was executed on.

Rules

• No shutting down by resource exhaustion (e.g.: forkbomb to force shutdown)
• You are allowed to write code that only works in a specific environment/OS, if you wish.
• Standard loopholes are forbidden

This is , thus the lowest amount of bytes wins!

• I got friends, who do this in school and think they are 'hacking' :D – RaisingAgent Jan 24 '17 at 14:00
• We should come up with some rule once to stop such whatever; Bash/Perl/PHP/Ruby/etc. stupiglots. – manatwork Jan 24 '17 at 14:22
• Windows, 0 bytes. Leave the computer on for a few days and let automatic updates do their work – Luis Mendo Jan 24 '17 at 15:17
• Anybody else notice the lack of TIO-links? – steenbergh Jan 24 '17 at 16:37
• @MontyHarder After reading that page I have decided to coin the term shatdown: past tense of the verb shutdown – FGreg Jan 24 '17 at 17:34

Assembly (x86/x64, Linux, as), 2221 19 bytes

mov  $0x58, %al # 2 bytes: b0 58 mov$0xfee1dead, %ebx # 5 bytes: bb ad de e1 fe
mov  $0x28121969, %ecx # 5 bytes: b9 69 19 12 28 mov$0x4321fedc, %edx # 5 bytes: ba dc fe 21 43
int  $0x80 # 2 bytes: cd 80  Must be run as root. This is equivalent to pressing the power button and not a safe way to power off your PC. Make sure you close all open applications and execute sync to flush all file system buffers before executing this program, to at least minimize the risk of file corruption. Test run $ as -o poweroff.o poweroff.s
$ld -o poweroff poweroff.o ld: warning: cannot find entry symbol _start; defaulting to 0000000000400078$ sudo sh -c 'sync && ./poweroff'


Followed by darkness.

How it works

int $0x80 invokes a software interrupt. It works on both x86 and x64, but has been deprecated for over a decade now and should not be used in production code. x64 code should use syscall instead. x86 should use sysenter, but it is too cumbersome for code golf. The resulting action from the syscall depends on registers EAX - EDX, ESI, and EDI. The Linux Syscall Reference shows all syscalls that are available via int$0x80.

When EAX holds 0x58 (88), reboot is called, which can also be used to power off, put to sleep, or hibernate the computer, as well as switching kernels and disabling or enabling the Ctrl - Alt - Del key combo.

At the start of the program – and by compiling with as or gcc -nostdlib, we can make sure that we're actually at the start of the program – most registers are set to 0. This includes EAX, so we can use mov $0x58, %al to set the lower 8 bits of EAX to 0x58, thus setting EAX itself to 0x58. This saves two bytes over manually zeroing the register with xor %eax, %eax and one more over the straighforward mov$0x58, %eax which encodes 0x58 in 32 bits.

The first two arguments to reboot are magic numbers, presumably to prevent accidental reboots, and are read from registers EBX and ECX. Unless these numbers are equal to certain constants, reboot refuses to perform any action.

• The first magic number must equal 0xfee1dead (feel dead), probably referring to the power off / death of the PC.

• The second magic number can be equal to four different constants, although the latter three did not work in ancient versions of Linux. All of them seem to refer to the subsequent power on / birth of the PC.

• 0x28121969 represents Linus Torvalds's birthday (December 28, 1969).

• 0x05121996 represents Patricia Torvalds's birthday (December 5, 1996).

• 0x16041998 represents Daniela Torvalds's birthday (April 16, 1998).

• 0x20112000 represents Celeste Torvalds's birthday (November 20, 2000).

Patricia, Daniela, and Celeste Torvalds are Linus Torvalds's three daughters.

• The EDX register selects the type of "reboot" we want. 0x4321fedc is RB_POWER_OFF, shutting the PC down and powering it off.

• Finally, the value of the ESI register is ignored for RB_POWER_OFF; the value of the EDI register is ignored entirely by reboot.

Alternate version, x64-only, 19 bytes

On x64, we can use a proper syscall for the same byte count.

mov     $0xa9, %al # 2 bytes: b0 a9 mov$0xfee1dead, %edi # 5 bytes: bf ad de e1 fe
mov     $0x28121969, %esi # 5 bytes: be 69 19 12 28 mov$0x4321fedc, %edx # 5 bytes: ba dc fe 21 43
syscall                   # 2 bytes: 0f 05


The only differences lie in the instruction (syscall vs int $0x80), the value of __NR_REBOOT (0xa9 vs 0x58), and the involved registers. • Do we normally count assembly as compiled bytes without the framing bytes required for exe header? – Joshua Jan 28 '17 at 14:42 • Yes, because each instruction corresponds to specific bytes in the binary file. ELF files (or whatever format your OS uses) are considered a different language and would have to be created manually to achieve a decent score. – Dennis Jan 28 '17 at 16:41 • Could you add the hex dump after assembly of the code? – ckjbgames Feb 13 '17 at 16:05 • @ckjbgames Here it is. – Dennis Feb 13 '17 at 19:21 • I fee1 so dead right now. – arminb Jun 27 '18 at 14:42 PowerShell, 13 bytes Stop-Computer  Pretty self-explanatory? Doesn't work on PowerShell core, so it won't work on PowerShell for Linux/MacOS (already tried it on TIO :-D ). Bonus Garbage Submission, 12 bytes gcm s*r|iex  In my testing, this works on Windows 2003 with PowerShell 2.0. It won't work on most of the newer versions, and it may not work depending on which modules are installed. It's quite terrible! This searches the list of commands for any with the pattern s*r and then runs all of them! To be clear, this is dangerous, don't do this! The trick of course, is getting a list of commands that don't have any mandatory parameters, otherwise PowerShell will prompt for a value. On my 2003 machine, the 3 commands it returns are: CommandType Name Definition ----------- ---- ---------- Application scrnsave.scr C:\WINDOWS\system32\scrnsave.scr Application ssmarque.scr C:\WINDOWS\system32\ssmarque.scr Cmdlet Stop-Computer Stop-Computer [[-ComputerName] <String[]>] [[-Cr...  Yes, it does launch the marquee screensaver, but no, it does not wait for it to complete before launching Stop-Computer. This approach can work on newer machines, again depending on which modules are installed, but the best I could do on Windows 2012 and 2016 was 14 bytes: gcm sto*er|iex  (and yeah, sure, the winbatch submission will work in PowerShell and it's shorter, but.. that's no fun) • Shorter one for Win7 & Win10 (and maybe more): gcm *p-c*|iex -- and there's only the one result too! – Bob Jan 25 '17 at 4:33 • @Bob highly dependent on installed modules still; on my Win10 machine it returns 6 results, several of which will have mandatory parameters (so they'll prompt and never make it to Stop-Computer, which is the last result). – briantist Jan 25 '17 at 14:52 Batch, 10 bytes On windows, this would suffice shutdown/s  This will set up a shutdown in one minute. Alternatively, as @flashbang points out: shutdown/p  This shuts down the computer immediately. • Press the big button on the front of your computer = 0 bytes – RaisingAgent Jan 24 '17 at 13:53 • @RaisingAgent Here at PPCG we solve our problems in code. Physical labour is frowned upon. – steenbergh Jan 24 '17 at 13:54 • @steenbergh I don't know... pressing one big button vs 10 keystrokes? I'll go with the button – WorldSEnder Jan 24 '17 at 21:01 • @RaisingAgent Your proposal has scalability issues. Try doing it for 10.000 computers four times a week. – Emilio M Bumachar Jan 26 '17 at 12:14 • @RaisingAgent real men use the switch that's right on the PSU – Cruncher Jan 26 '17 at 14:18 x86 machine code, Lenovo Z510, DOS COM or Bootloader, 7 bytes BITS 16 mov ax, (1 << 13) | (7 << 10) mov dx, 1804h out dx, ax  Assembled into B8 00 3C BA 04 18 EF I'm exploiting "You are allowed to write code that only works in a specific environment/OS, if you wish" to the ultimate level: this will only work on Lenovo Z5101. This writes SLP_TYPa << 10 | SLP_EN to the PM1a_CNT ACPI register, I dumped this values from the ACPI tables months ago for an answer about shutdown (where I give a bit of context to the code above). This can be run either under DOS as a COM (just write the binary data into a file and change extension to "com") or as a bootloader. For the latter write the standard signature and beware of the issues with modern firmware. 1 Not strictly true, any system that happens to have the same ACPI configuration will also shutdown. • Upvoted because of the limited platform. – pipe Jan 26 '17 at 14:39 • Ha! Somebody beat Dennis! – Joshua Jan 30 '17 at 16:57 • If you're going with the 7-byte count, you should call this a machine code submission rather than an assembly solution. The assembly submission is 63 bytes. – Jakob Jun 26 '18 at 19:03 • @Jakob You are right! – Margaret Bloom Jun 26 '18 at 21:26 • You look like the right person to answer this question: stackoverflow.com/questions/2019463/… (I failed miserably at it, had to delete my "answer" out of shame.) – Prof. Falken Sep 3 '18 at 12:40 GRUB shell, 4 bytes Golfed halt  Command: halt --no-apm The command halts the computer. If the --no-apm option is specified, no APM BIOS call is performed. Otherwise, the computer is shut down using APM. Bonus Here is a proof that GRUB shell is indeed Turning-complete (see comments): • grub shell is not a "programming language" - it's not Turing complete – Alnitak Jan 25 '17 at 11:38 • @Alnitak, what makes you think so ? It features a rather advanced built-in scripting language, which has a syntax quite similar to that of GNU Bash and other Bourne shell derivatives and supports variables, conditional constructs, functions and more, so obviously, it is Turning-complete, by any measure. – zeppelin Jan 25 '17 at 12:17 • OK, I'll take that back - I didn't find that stuff when I looked – Alnitak Jan 25 '17 at 12:32 • When it cannot display a spinner it is obviously not Turning-complete – J_F_B_M Jan 26 '17 at 11:31 • In Bash it's the same command. – Paweł Tokarz Jan 30 '17 at 10:55 65C02 machine code, 1 byte STP instruction (0xDB): STP stops the clock input of the 65C02, effectively shutting down the 65C02 until a hardware reset occurs (i.e. the RES pin goes low). This puts the 65C02 into a low power state. This is useful for applications (circuits) that require low power consumption, but STP is rarely seen otherwise. xxd dump: 00000000: db .  • Noice. I was an Apple II hacker back in the day and didn't even remember this opcode. – kindall Jan 25 '17 at 19:06 • Yeah, after writing a 65c816 emulator with more features and saw this challenge I knew what to do :P Also, looks like this is the only 1 byte answer so far! \o/ – 2xsaiko Jan 25 '17 at 19:17 Matlab, 21 Bytes system('shutdown -s')  I haven't tried this (closing all programs to do a restart in the middle of the day isn't really tempting), but it should work.. This works... I'll add a short explanation later, my laptop is currently off. • "I'll add a short explanation later, my laptop is currently off." <- The danger of a shutdown challenge – Suever Jan 24 '17 at 14:08 • Axaxaxaxa, well, restarting your computer every once in a while can't be bad :) – RaisingAgent Jan 24 '17 at 14:14 • Does ruin your uptime, though – Wayne Werner Jan 26 '17 at 19:02 • Why submit this as MATLAB, instead of submitting shutdown -s as shell? – user253751 Jan 27 '17 at 5:50 • Because for me, shell is either something I find on the beach, or a gas station. – Stewie Griffin Jan 27 '17 at 7:18 MATLAB, 11 bytes !shutdown/p  Somewhat similar to Stewie Griffin's approach. However, MATLAB has way shorter ways of invoking system commands; in this case, ! is used. Windows does not need .exe for command names, so that's left out as well. The / option is still supported (I'm running Windows 10), and negates the need for the space. Alternatives are: system shutdown/p % 17 bytes; uses so-called 'command' syntax. dos shutdown/p % 14 bytes; the 'dos' command can be used just as well.  SmileBASIC, 1411 6 bytes OPTION  Triggers a crash causing the 3DS to restart. I hope this counts. Works in the most recent version. • I thought this had been patched... Please include a version number. – wizzwizz4 Jan 24 '17 at 19:05 • It has been patched in version 3.5, which hasn't been released outside of Japan yet. – 12Me21 Jan 24 '17 at 19:35 • @12Me21 Sure it counts. Nice choice of environment. – P. Ktinos Jan 24 '17 at 21:46 • If only REBOOT from SBv2 counted as a valid answer. – snail_ Jun 27 '18 at 4:09 Bash, 7 6 bytes init 0  Assuming that the program is run as root. • Indeed, powering off the machine is required. Thus you need 'halt -p' as a valid answer – P. Ktinos Jan 24 '17 at 14:07 • This editing massacre :) – RaisingAgent Jan 24 '17 at 14:08 • @P.Ktinos: poweroff is a single word, although slightly more letters. – ccpizza Jan 27 '17 at 12:32 • @ccpizza Right, but the typical scoring criteria is byte count – Suever Jan 27 '17 at 14:45 • Also, init 6 would restart the machine, but not sure that would completely count as "turning off." – Chipster Nov 2 '19 at 5:42 Commodore 64, 11 bytes 0 sys64738  This is from the BASIC prompt. Or... Commodore 64, 6502 assembly, 3 bytes (assembled), 16 bytes (source) *=8000 JMP$FCE2

• I think that using the Commodore 64's direct input mode from BASIC with sys64738 will use zero bytes as there is no program or anything else to store; You are using screen RAM but that RAM will already be filled with spaces, so you're just replacing those spaces with text. – Shaun Bebbers Jan 24 '17 at 17:03
• The source code takes up space. Just because it doesn't reserve space on the target machine doesn't mean it takes up 0 bytes. Otherwise the answer would be . – wizzwizz4 Jan 24 '17 at 18:24
• You don't need the space between the 0 and the sys64738, you can replace the sys with the shortcut form sY, and I don't count the trailing newline in program length. However, I don't think your code meets the requirements: the code at 64738 does a soft reset, not a poweroff. – Mark Jan 24 '17 at 22:46
• Does not power off. – TecBrat Jan 27 '17 at 15:03
• I once spilled beer on my Commodore 64, that powered it off permanently. Does this count? – Shaun Bebbers Jan 27 '17 at 15:06

Python 2, 29 bytes

import os;os.system('init 0')


Works on Linux systems and needs root privileges.

For Windows, 33 bytes

import os;os.system('shutdown/p')

• Someone else posted the Linux shell version. – jpmc26 Jan 25 '17 at 1:34
• Ah ok, my bad.. – FlipTack Jan 26 '17 at 19:59

Java, 1019862 42 bytes

()->{Runtime.getRuntime().exec("init 0");}


As @Snowman pointed out, the question didn't specify if a full program was needed, so this should still be acceptable.

• It's shorter to replace class with interface as that allows you to omit public from main. – Pavel Jan 24 '17 at 15:42
• You can use a method, since the question did not specify the submission must be a full program: void f()throws Exception{Runtime.getRuntime().exec("shutdown/s");} – user18932 Jan 24 '17 at 18:12
• Wouldn't the Linux version be a bit shorter? – jpmc26 Jan 25 '17 at 1:32
• ()->{Runtime.getRuntime().exec("init 0");} or tentatively ()->Runtime.getRuntime().exec("init 0") (can't check at the moment). It's a lambda implementing a custom void, no-args-throwing interface. – Olivier Grégoire Jan 26 '17 at 12:23
• This should be labeled as a Linux-specific answer, e.g. "Java on LInux". – Jakob Jun 26 '18 at 19:05

AppleScript, 30 bytes

tell app "Finder" to shut down


Does exactly what it says: tells Finder to shut the computer off.

TI-Nspire CX CAS, 3 bytes

" "+" "


summing two empty strings.

On an older version of the calculator, this would crash the device and cause it to reboot (there's no way to shutdown a device without reboot apart from physical button combinations).

• Isn't that 7 bytes? – Roman Gräf Jan 26 '17 at 14:52
• – devRicher Jan 26 '17 at 14:55
• Sounds convincing to me. – Roman Gräf Jan 26 '17 at 14:58

C++, 51 40 bytes

-11 bytes thanks to Ingve!

#include<os>
int main(){OS::shutdown();}


Only works in IncludeOS (v0.10.0-rc.1)

Test:

$pwd /home/simon/IncludeOS/examples/demo_service$ cat service.cpp
#include<os>
int main(){OS::shutdown();}

$mkdir build && cd build && cmake .. && make && cd .. [...]$ boot build/IncludeOS_example
[...]
================================================================================
================================================================================
IncludeOS v0.10.0-rc.1-9-g151a2b9
+--> Running [ IncludeOS minimal example ]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

\$

• Now i am curious about IncludeOS – Karl Napf Jan 25 '17 at 19:57
• @KarlNapf Alfred held a great presentation at CppCon 2016 about IncludeOS: youtube.com/watch?v=t4etEwG2_LY if you want to know more :-) – simon Jan 25 '17 at 20:05
• You don't need to use void Service::start, int main works in IncludeOS as well. – Ingve Jan 27 '17 at 10:56

AutoHotkey, 11 10 Bytes

Saved a byte thanks to Gurupad Mamadapur

Shutdown,9


AHK Supports a Shutdown command by default. The 9 is a flag, consisting of Shutdown=1 + PowerDown=8.

• AHK is mysterious. – Gurupad Mamadapur Jan 25 '17 at 14:35
• Do you need the space after the comma? – 2xsaiko Jan 26 '17 at 15:34
• space after , is not needed. Try testing it with a different flag. I thought this will not immediately shut down the computer, and put it in my main script which loads at startup :D Now I've to load in safe mode and solve the problem. Sigh. – Gurupad Mamadapur Jan 26 '17 at 15:52

Machine code (x86, boot loader) 18 bytes

b8 01 53 33 db cd 15 b8 07 53 bb 01 00 b9 03 00 cd 15


Disassembly:

mov ax, 0x5301 ; connect to real-mode APM services
xor bx, bx     ; device id 0 - APM BIOS
int 0x15       ; call APM
mov ax, 0x5307 ; set power state
mov bx, 0x0001 ; on all devices
mov cx, 0x0003 ; to Off
int 0x15       ; call APM


You can test it in Bochs' debugger with the following commands (after starting simulation, having some disk drive set up):

pb 0x7c00
c
setpmem 0x7c00 4 0x335301b8
setpmem 0x7c04 4 0xb815cddb
setpmem 0x7c08 4 0x01bb5307
setpmem 0x7c0c 4 0x0003b900
setpmem 0x7c10 2 0x15cd
c


This same machine code will also work as a DOS executable (*.COM).

C#, 7954 53 bytes

This works on Windows.

79 bytes:

class _{static void Main(){System.Diagnostics.Process.Start("shutdown","/s");}}


53 bytes, thanks to TheLethalCoder:

_=>System.Diagnostics.Process.Start("shutdown","/s");

• Note the challenge doesn't require a full program and doesn't disallow taking an input (unused of course) so you could compile to an Action<int> and do _=>System.Diagnostics.Process.Start("shutdown", "/s"); for 54 bytes. – TheLethalCoder Jan 25 '17 at 14:18
• @TheLethalCoder, updated, thanks! – Dariusz Woźniak Jan 25 '17 at 15:57
• You can also remove the unnecessary space. – nothrow Jan 27 '17 at 20:59
• Of course yes! Thank you, @nothrow :) – Dariusz Woźniak Jan 27 '17 at 22:38

AutoIt, 11 bytes

Shutdown(1)


Shutdown function gets combination of following codes

0 = Logoff
1 = Shutdown
2 = Reboot
4 = Force
8 = Power down
16= Force if hung
32= Standby
64= Hibernate


To shutdown and power down, for example, the code would be 9 (shutdown + power down = 1 + 8 = 9).

• 0 (logoff) is a special case here; it does not combine with Standby or Hibernate implicitly. – wizzwizz4 Jan 24 '17 at 19:02
• OK 0 + 32 = 32 – rahnema1 Jan 24 '17 at 19:25
• Hm, so does it always log off before going to standby/hibernation? – Ruslan Jan 29 '17 at 6:30
• @Ruslan I do not know exactly how it works, You can refer to AutoIt user forum to receive more feedbacks:-) – rahnema1 Jan 29 '17 at 7:05

Windows - NativeAPI, 212 bytes

Ok this is not really the shortest version. But maybe interesting to some. This will not execute on the Win32 subsystem. However it will run when executed within the context of the native api (like autochk.exe does)

Code

#define WIN32_NO_STATUS
#include <windef.h>
#include <winnt.h>
#include <ntndk.h>
NTSTATUS main() {
return ZwShutdownSystem(ShutdownPowerOff);
}


Build

To build this either use the WinDDK build.exe tool (with an appropriate source file for NMAKE)

Or use these commands to compile and link:

cl /Gd /D_X86_ /showIncludes /I%DDK_INC_PATH% /I%CRT_INC_PATH% /c main.c
link /verbose /nodefaultlib /subsystem:native /machine:X86 /entry:NtProcessStartup@4 C:\WinDDK\7600.16385.1\lib\win7\i386\nt.lib C:\WinDDK\7600.16385.1\lib\win7\i386\ntdllp.lib C:\WinDDK\7600.16385.1\lib\win7\i386\BufferOverflow.lib .\main.obj


Note: This will build an x86 native executable. Change the appropriate bits if you want to build this for a different architecture.

Test

To test a native executable you have to execute it before the win32 subsystem is loaded. One common way to do it is to append the executable in the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\BootExecute


Warning

If you do this however, you need to have an option to edit the registry hive of the target OS from another OS. Since you will not be able to boot the target OS anymore!

I did it on a VM where i could easily revert to a previous snapshot!

Groovy, 23 bytes

'shutdown /p'.execute()

• Is the space before the slash necessary? – steenbergh Jan 24 '17 at 14:12
• @steenbergh Yes, it is needed. – Gurupad Mamadapur Jan 24 '17 at 14:32
• @GurupadMamadapur are you sure? – TrojanByAccident Jan 24 '17 at 19:48

Most Linux shells, 15 bytes

# echo o>/p*/*ger


It could be made to be 11 bytes long, if you happen to be in the /proc directory:

# echo o>*ger


This is very straightforward (has no side effects, like unmounting filesystems or killing processes) and rather brutal.

• Last time I tried wildcard expansion on redirect it generated a file with the wildcard in it despite a matching file existing. – Joshua Jan 25 '17 at 18:57
• I believe you have to add "/proc/" to your byte count – zeppelin Jan 25 '17 at 20:49
• @Joshua It might be shell dependent. I actually tested it (with bash) on my computer :-) – Radovan Garabík Jan 25 '17 at 21:12
• @Radovan Garabík - I don't think that is really valid. This is basically the same as implying that there is an alias "p=poweroff" (which is not "impossible" too) and claiming "p" to be a valid 1 byte solution. – zeppelin Jan 26 '17 at 14:52
• But you can probably make it valid at expense of just 3 bytes, like this echo o>/p*/*ger – zeppelin Jan 26 '17 at 15:40

Android shell, 9 bytes

reboot -p

• Welcome to PPCG! – ETHproductions Jan 29 '17 at 20:46

AppleScript, 44 bytes

tell application "Finder"
shut down
end tell


I don't know how AppleScript syntax works or anything, so if anybody knows how to shorten this, please tell.

Also, I'm doing this on my phone at school ("hacking"), so I can't test it.

At 14 fewer bytes (thanks to kindall) you can say

tell app "Finder" to shut down

• Someone came up with a shorter solution (with same program) a few hours after you (but posted it instead of commenting here) codegolf.stackexchange.com/a/107958/62824 – devRicher Jan 25 '17 at 11:08
• You can probably remove the indentation – Cyoce Jan 25 '17 at 15:52
• tell app "Finder" to shut down should work, I believe (though the compilation may replace 'app' with 'application'). – kindall Jan 25 '17 at 19:04

J, 14 bytes

2!:0'poweroff'


Works on Linux systems. 2!:0 executes the string in /bin/sh.

Clojure, 40 39 bytes

(.exec(Runtime/getRuntime)"shutdown/s")


-1 byte by changing the flag from -s to /s, which allowed me to get rid of the space.

Basically the Java answer.

Testing this was fun. Windows decided to do a firmware update on my Surface the second it shut down. Of course.

(defn shutdown []
(.exec (Runtime/getRuntime) "shutdown -s"))


Node.js, 39 bytes

Linux

require('child_process').exec('init 0')


AHK, 19 15 bytes

Run,Shutdown -s


Works on windows only.

C++, 48 47 (Windows) 46 45 (Linux) bytes

Removed 1 byte thanks to Snowman

#include<cstdlib>
main(){system("shutdown/p");}


This should shutdown the system for windows

#include<cstdlib>
main(){system("poweroff");}


This should shutdown the system for Linux

• do you need the ;? – RaisingAgent Jan 24 '17 at 14:12
• @LliwTelracs Pretty sure it is "shutdown /p" and not "-p" and the space is not needed. – P. Ktinos Jan 24 '17 at 14:14
• The semicolon is required for proper c++ syntax, using a slash allows for a shorter answer for windows but makes it no longer work for linux. Although I added the wrong character for shutdown that is shared between windows and linux – fəˈnɛtɪk Jan 24 '17 at 14:21
• @LliwTelracs Although you can do whatever you want, I suggest abusing the 2nd rule and not caring about Linux functionality, since this is a code-golf and low amount of bytes is better. – P. Ktinos Jan 24 '17 at 14:25
• #include<cstdlib> will shave off a byte. – user18932 Jan 24 '17 at 18:14