38
votes
\$\begingroup\$

I'm searching (am I?) for a piece of code that quits immediately - in an absolutely unconventional way.

This does not mean: System.exit((int) 'A'); (Java).

It might mean:

#!/usr/bin/env python3
# NOTE: This kills ALL RUNNING Python processes. Be careful!
def exit():
    import os
    os.system("killall python3")
    # Windows addon
    os.system("taskkill /im python.exe /f")
exit()

Most upvoted answer wins! All languages, all architectures.

Edit: Quitting by throwing exceptions won't be accepted any more!

\$\endgroup\$
11
  • 3
    \$\begingroup\$ But thats not unconventional to end execution... Well, it's an alternative to exit(), but still it's an implemented feature... \$\endgroup\$
    – s3lph
    Dec 28, 2013 at 21:25
  • 13
    \$\begingroup\$ This isn't code-trolling - we know we want weird answers from this one. \$\endgroup\$ Dec 28, 2013 at 22:36
  • 6
    \$\begingroup\$ Does shutting the system down work? \$\endgroup\$
    – user10766
    Dec 29, 2013 at 0:42
  • 8
    \$\begingroup\$ I once accidentally caused a network card to DMA over the operating system. When it happened you were instantly back in the BIOS, rebooting. \$\endgroup\$ Dec 29, 2013 at 0:52
  • 3
    \$\begingroup\$ I feel like Shannon has us beat here ;) \$\endgroup\$ Dec 29, 2013 at 6:33

86 Answers 86

44
votes
\$\begingroup\$

Bash

echo "Turn off your computer or i'll wipe your harddrive..."
echo 3;sleep 1
echo 2;sleep 1
echo 1;sleep 1
dd if=/dev/random of=/dev/hda

Terminates the program as fast as the user can react ;-)

\$\endgroup\$
3
  • 10
    \$\begingroup\$ Upvoting because it made me laugh. \$\endgroup\$ Feb 13, 2014 at 15:19
  • 5
    \$\begingroup\$ Better do not run it on Linux. \$\endgroup\$
    – kenorb
    Jul 2, 2014 at 15:48
  • 1
    \$\begingroup\$ dd: /dev/hda: not found \$\endgroup\$
    – Joshua
    Oct 20, 2015 at 16:57
43
votes
\$\begingroup\$

bash, 6 characters

exec [

exec replaces the current process with something else. [ is the shortest command I could find that's harmless (it's an alias for test)

\$\endgroup\$
5
  • \$\begingroup\$ An other exception? \$\endgroup\$ Dec 28, 2013 at 21:22
  • \$\begingroup\$ No, just exec'ing the [ command :) \$\endgroup\$ Dec 28, 2013 at 21:23
  • 1
    \$\begingroup\$ why is it working? what does [ do? \$\endgroup\$
    – s3lph
    Dec 28, 2013 at 21:23
  • \$\begingroup\$ @the_Seppi it replaces the current process with [ (aka test) \$\endgroup\$
    – Timtech
    Dec 28, 2013 at 23:29
  • \$\begingroup\$ ~ $ echo $PATH/? -> /bin/X /bin/[ /bin/w. Fish shell gave me two other commands. w is interesting in my opinion. \$\endgroup\$
    – 0..
    Dec 30, 2013 at 8:40
39
votes
\$\begingroup\$

Redcode

(Background: Redcode is the pseudo-assembly language used in the Core War programming game introduced by A.K. Dewdney in 1984. It typically makes heavy use of self-modifying code. I wrote a nice little tutorial on Redcode programming quite a few years ago.)

MOV 1, 0

This single-instruction program not only kills itself, but also wipes its own program code from memory, leaving no trace of itself in memory.

Boring, you say? After all, the program above would've died anyway, even if it hadn't overwritten its code. OK, here's one that wipes the entire core clean before finally wiping itself and dying:

loop: MOV  ptr+1, >ptr 
      JMN  loop, loop
      SPL  1
      SPL  1
      MOV  ptr+1, >ptr
ptr:  DAT  0, 1

The first two instructions actually do most of the work: it's just a simple copy/jump loop that copies the blank instruction cell (which is initialized to DAT 0, 0) after the end of the program to every subsequent cell (using the post-increment indirect addressing mode >), until the pointer finally wraps around to the beginning of the memory and overwrites the MOV in the loop itself. Once that happens, the JMN (JuMp if Not zero) detects it and falls through.

The problem is that this still leaves the JMN itself unwiped. To get rid of it, we need another MOV to wipe the JMN... but that means we need yet another MOV to wipe that MOV, and so on. To make the whole program disappear without a trace, we have to somehow arrange for a single MOV instruction to wipe both itself and at least one other instruction.

That's where the SPL comes in — it's one of the weirdest opcodes in Redcode. Basically, it's a "Branch Both Ways" instruction. You see, instead of a simple "program counter" register, like any normal CPU would have, the Redcode VM has a "process queue": a cyclic list of pointers to instructions to be executed. Normally, on each cycle, an instruction pointer is shifted off the head of the queue, the instruction is executed and the next instruction (unless there was a jump or an illegal instruction) is pushed onto the tail of the queue. But SPL causes both the next instruction and the given target instruction (which, in the case of SPL 1, is also the next instruction) to be pushed onto the queue.

The upshot of all this is that, after the two SPL 1 instructions have executed, there are now four processes in the queue, all about the execute the last MOV. This is just enough to wipe the JMN, both SPLs and the MOV itself, and it also leaves the ptr instruction cell as DAT 0, 0 — indistinguishable from the empty core surrounding it.

(Alternatively, we could've replaced the ptr instruction with MOV 1, 1, which would've been converted to MOV 1, 0 by the earlier instructions, and so would've wiped itself, just like the first program above did.)

Ps. If you want to test these program, download a Redcode simulator (a.k.a. MARS). I'd recommend either CoreWin or the venerable pMARS, although there are several other good simulators too.

\$\endgroup\$
5
  • \$\begingroup\$ Won'tthis simply throw an access violation? \$\endgroup\$ Dec 29, 2013 at 6:38
  • 12
    \$\begingroup\$ Access violation? What manner of strange thing is that? (Seriously, Redcode runs in a pretty abstract VM. All addressing is relative, the address space is contiguous (and cyclic) and every address is valid.) \$\endgroup\$ Dec 29, 2013 at 16:22
  • \$\begingroup\$ Does MOV 1, 0 copy 1 into address 0 or the other way around? In all the assembler languages I know address 0 is illegal (NULL address). \$\endgroup\$ Dec 29, 2013 at 19:44
  • 4
    \$\begingroup\$ The syntax is MOV source, dest. But as I said, all addressing in Redcode is relative, so the address 0 actually means "the address of this instruction", while the address 1 actually means "the address of this instruction + 1". (And the absolute address 0 isn't in any way special in Redcode anyway; in fact, one interesting consequence of the "all relative addressing" design is that it's actually impossible for a Redcode program to find its own absolute address in the core!) \$\endgroup\$ Dec 29, 2013 at 20:12
  • 2
    \$\begingroup\$ Man, I'm so grateful to you. I had never heard about Core War. \$\endgroup\$
    – seequ
    Jul 9, 2014 at 14:03
32
votes
\$\begingroup\$

C

#include <conio.h>  /* Computer-Operated Nuclear Installation Options */
int main () {
    clrscr();       /* Commence Launch (Remote Systems Console Request) */
    kbhit();        /* Keep Busy until hit */
}

Note that this is not portable code. It works with ZOG C on the ART DS9000. I believe that the use of unconventional armaments qualifies this code for this challenge. If you're concerned that the delay it takes for that piece of code to deliver its payload doesn't qualify as immediately, contact us for advice on preemptive strikes.

effect of launch

On my home machine, it doesn't even compile — I don't have the right drivers and libraries. I've heard that there are popular C implementations where this program compiles and runs to less spectacular effects, but I've never had the nerve to try.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Best answer, hands down! \$\endgroup\$
    – Vector
    Jan 5, 2014 at 5:48
  • 3
    \$\begingroup\$ +1.(0)1 ; at first, I thought @Gilles is trolling here... but then I checked the ART Inc. webpage... and it was then when I realized how heavily I was trolled! \$\endgroup\$
    – user18967
    Jun 8, 2014 at 14:19
30
votes
\$\begingroup\$

JavaScript

window.location.replace("http://pieisgood.org");

Simply navigates to a different (delicious) website. :-)

Golfed (10 chars):

location=1
\$\endgroup\$
1
  • 7
    \$\begingroup\$ mmmm, ice-cream :P \$\endgroup\$
    – Volatility
    Dec 28, 2013 at 21:45
28
votes
\$\begingroup\$

C#

Kills itself by killing every process but itself.

foreach (Process p in Process.GetProcesses()) {
    string myexe = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
    if (p.ProcessName == myexe) continue;
    p.Kill();
}

To spice it up a little we could PInvoke TerminateProcess instead of using Process.Kill

\$\endgroup\$
6
  • 4
    \$\begingroup\$ +1 for very unconventional method of killing every single other thing, thus causing your own program to go down with the system (or at least, I assume that's the idea?). I don't have a C# runtime on this machine, but I've got to ask... In practice, does this end up taking the system down or just all running processes? (I thought C# programs invoked the interpreter themselves, thus not relying on the existence of a particular JIT/CIL process...). Again, great job thinking 'outside the box' (har har) on this one :) \$\endgroup\$ Dec 29, 2013 at 6:14
  • 4
    \$\begingroup\$ -1 (if I had the rep): The meta on code trolling says that destructive answers aren't allowed because of the risk of people trying them on their own machines. See the second bullet in the list of restrictions: codegolf.stackexchange.com/tags/code-trolling/info \$\endgroup\$
    – Kevin
    Dec 29, 2013 at 16:08
  • \$\begingroup\$ System processes can't be killed without admin rights, aren't they? \$\endgroup\$ Dec 29, 2013 at 17:33
  • 3
    \$\begingroup\$ @Kevin code-challenge and code-trolling are different tags with different rules. \$\endgroup\$
    – osvein
    Dec 30, 2013 at 0:24
  • 3
    \$\begingroup\$ @user1981338: the question originally had the code-trolling tag, but it has since been edited out. Now that the tag's gone, +1. \$\endgroup\$
    – Kevin
    Dec 30, 2013 at 4:01
20
votes
\$\begingroup\$

BASH - 12 characters

:(){ :|:&};:

Classic forkbomb. Locks up the computer and forces user (or admin) to reboot.

\$\endgroup\$
7
  • 5
    \$\begingroup\$ Boring - but still my personal favorite. I use this to shut down live systems \$\endgroup\$
    – s3lph
    Dec 29, 2013 at 11:25
  • 3
    \$\begingroup\$ It starts itself as many times as it can, that's not quitting. \$\endgroup\$
    – marinus
    Dec 29, 2013 at 13:06
  • 1
    \$\begingroup\$ But it will start as many processes as possible until the computer crashes and therefore quits the program \$\endgroup\$
    – s3lph
    Dec 29, 2013 at 14:16
  • 14
    \$\begingroup\$ +1 for adding smileys such as :() and :| \$\endgroup\$
    – ProgramFOX
    Dec 29, 2013 at 18:06
  • 1
    \$\begingroup\$ @Kartik: Without the first space, you'll get a syntax error. You can eliminate the second one. \$\endgroup\$
    – Dennis
    Dec 29, 2013 at 18:48
20
votes
\$\begingroup\$

Python (on old laptops)

On old laptops with single core processors and bad cooling:

while True:
    print("CPU Temperature rising")

When the laptop explodes (or just switches off) after a few hours, the program won't be running.

(For best results, wrap the laptop in a blanket or something)

\$\endgroup\$
18
votes
\$\begingroup\$

Ruby

kills the running ruby/irb process on *nix.

`kill #{$$}`
\$\endgroup\$
1
  • 2
    \$\begingroup\$ I like the elegance of this one. +1 \$\endgroup\$
    – Doorknob
    Dec 29, 2013 at 1:22
18
votes
\$\begingroup\$

Apple 2 Basic

1 PRINT "HELLO"
2 POKE 2053,128
3 POKE 2054,58
4 GOTO 1

It overwrites one of its instructions with an END.

\$\endgroup\$
2
  • \$\begingroup\$ How does this one work? \$\endgroup\$
    – Johannes
    Dec 31, 2013 at 1:53
  • 5
    \$\begingroup\$ @Johannes: in Applesoft BASIC, the program is stored in a tokenized form in memory. Because there's no OS or memory protection, it's always stored in the same place and there's nothing to stop you from writing to that memory. So the first POKE writes an END token over the PRINT token, and then the second POKE writes a command terminator over the first ". When the GOTO is executed, it ends up running END instead of PRINT and the program ends. \$\endgroup\$
    – marinus
    Dec 31, 2013 at 5:59
13
votes
\$\begingroup\$

In assembly, something like this would probably work:

jmp 0

I remember that compiles this actually worked DOS. Back then, it rebooted the computer.

\$\endgroup\$
3
  • \$\begingroup\$ try ret; Actually I'm going to post this as an answer :P \$\endgroup\$ Dec 29, 2013 at 5:12
  • \$\begingroup\$ retf will work, I already put that in an answer :) It kills it because of the way memory segmentation works (or doesn't work, should I say) on modern operating systems \$\endgroup\$
    – chbaker0
    Dec 30, 2013 at 7:08
  • \$\begingroup\$ »jmp 0« works with DOS, 'cause the first two byte of a code segment was CD 20, or 'INT 20' which is the code for exit programm. »push 0; ret« whould have the same effect. \$\endgroup\$
    – Daniel
    Dec 31, 2013 at 14:08
12
votes
\$\begingroup\$

C, 9 chars

Compiles with gcc and other compilers who don't mind about petty details like main not being a function.
Works on x86 platforms - the program immediately exits.

main=195;

195 is the opcode of the ret instruction.

\$\endgroup\$
1
  • 4
    \$\begingroup\$ Segfaults for me. main is located in .data because it's an int, not in .text, and .data is loaded into an non-executable page. \$\endgroup\$
    – mniip
    Jan 1, 2014 at 15:04
12
votes
\$\begingroup\$

PHP

function quit(){unlink(__FILE__);posix_kill(getmypid(),15);}

Effects:
Deletes your crappy script file and then kills your program.
Throw one of these bad boys into some codebase to confuse people.

\$\endgroup\$
2
  • \$\begingroup\$ This is not valid PHP syntax. You try to define a function quit but the parameter list is code to run. I get a parse error when trying to run it. \$\endgroup\$ Jan 2, 2014 at 0:06
  • \$\begingroup\$ @EmilVikström - Fixed now. \$\endgroup\$ Jan 3, 2014 at 1:01
10
votes
\$\begingroup\$

I always wanted to post this somewhere, I guess it fits here even though there's already an accepted answer.

int
main(int argc, char **argv)
{
        revoke(*argv);
}

This works on any post 4.3BSD system and others that implement revoke in the same way. Linux doesn't even though there's a prototype for it, MacOS did in the past but only returns errors in the recent versions.

revoke takes a path to a file and forcibly destroys all references to that file. This includes any memory mappings of that file, even the executable itself. Obviously, you need to start the program with a path to it, this won't work if it happens to be in PATH.

A variation of this that should work on most unix-like systems is:

#include <sys/mman.h>
#include <inttypes.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
        intptr_t ps = getpagesize();
        munmap((void *)(((intptr_t)main)&~(ps - 1)), ps);
}

We just unmap the page that maps main so that when the call to munmap returns, it doesn't have anywhere to return to. There's a slight chance that the the function call to munmap is just on a page boundary and the return will succeed, so to be perfectly sure this works, we probably have to attempt to unmap two pages first.

And of course, a variation on the same theme:

#include <sys/mman.h>
#include <inttypes.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
        intptr_t ps = getpagesize();
        munmap((void *)(((intptr_t)&ps)&~(ps - 1)), ps);
}

Just unmap the stack so that we don't have anywhere to return to. Same caveat as unmapping main - we might need to unmap two pages, except that we have to remember that the stack probably grows down (unless you're on PA-RISC or some other strange architecture like that).

Another way to pull the rug from under your own feet:

#include <sys/resource.h>

int
main(int argc, char **argv)
{
        setrlimit(RLIMIT_CPU, &((struct rlimit){ 0 }));
        while(1);
}

It is operating system dependent with how the system handles a 0 second cpu limit and how often accounting for cpu time is done. MacOS kills the process immediately, Linux requires the while loop, another system I tried didn't do anything even with a one second limit and a while loop, I didn't debug further.

\$\endgroup\$
9
votes
\$\begingroup\$

sh

sudo kill -SEGV 1

Instant kernal panic on Linux. Destorys all processes, including itself

Cmd

pskill csrss.exe

Instant blue screen on Windows. Terminates the Client/Server Runtime SubSystem. Pskill must be installed.

\$\endgroup\$
4
  • \$\begingroup\$ Would killall init also work? \$\endgroup\$
    – s3lph
    Dec 29, 2013 at 11:36
  • 1
    \$\begingroup\$ @the_Seppi 1. Only a root-level user can send signals to init 2. Init will only cause a kernal panic if it receives signal 11 (segamentation fault) \$\endgroup\$ Dec 29, 2013 at 21:06
  • \$\begingroup\$ OK thank you... Do you know what happens if you use sudo killall init \$\endgroup\$
    – s3lph
    Dec 29, 2013 at 21:49
  • 1
    \$\begingroup\$ @the_Seppi Yes, I do, I have tried it before. Init ignores it, because init can decide whether it receives the signal or not, so it completely ignores SIGKILL. unix.stackexchange.com/questions/7441/… \$\endgroup\$ Dec 29, 2013 at 23:02
7
votes
\$\begingroup\$

Taking things literally in a silly way with Haskell:

import System.Exit

absolutely doThis = if True then doThis else undefined

unconventional doThat = do
  putStrLn "I could just do that"
  putStrLn "But I'm gonna print factorial of 100 first"
  putStrLn "There you go:"
  print $ fac 100
  doThat
  where fac n = foldl (*) 1 [1..n]

main = absolutely unconventional exitFailure
\$\endgroup\$
7
votes
\$\begingroup\$

In C (Compatible Windows / Linux / (probably Unix / Freed BSD too)):

main;

Usage example:

Under Windows compile with:

echo main; > main.c && cl /Fe:main.exe main.c

And Linux:

echo "main;" > main.c && gcc -w -o main main.c

Assuming the compiler is installed and in the currenth PATH variable.

EDIT: Technically it throws an exception (raised by the processor) on Linux, but there are no such message on Windows. So this entry probably is not valid; however I think it's cool :P

EDIT: In x86 assembler (using NAsm/YAsm)

global s
s:
    ret

Compile with:

(Windows)

nasm -f win32 -o test.obj test.asm
LINK /OUT:test.exe /SUBSYSTEM:CONSOLE /ENTRY:s test.obj

(Linux)

nasm -f elf32 -o test.obj test.asm
ld -o test -e s test.obj

Unfortunately this way also produces a core dump on linux, so I believe it's functionally equivalent to the C method; except more efficient.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Wow! I just compiled this with -Wall -Wextra -std=c99 -pedantic and there are no warnings at all. \$\endgroup\$
    – user11184
    Dec 29, 2013 at 6:33
  • \$\begingroup\$ I actually wanted to put this, but decided against, because it would be duplicate of my solution to different problem (codegolf.stackexchange.com/a/8778/3103). \$\endgroup\$
    – 0..
    Dec 30, 2013 at 8:36
6
votes
\$\begingroup\$

Python


Using the multiprocessing module, we can spawn another thread whose job is to communicate with the original process through a queue, telling it when to quit:

import multiprocessing
import time
queue = multiprocessing.Queue()

def second_thread():
    while True:
        queue.put('quit')
        time.sleep(0.1)

second_ps = multiprocessing.Process(target = second_thread)
second_ps.start()

while True:
    msg = queue.get()
    if msg == 'quit':
        break
    time.sleep(0.1)

second_ps.join()
\$\endgroup\$
6
votes
\$\begingroup\$

Okay. If simply calling System.exit isn't permitted in Java, how about calling it via reflection from another thread?

import java.lang.reflect.*;

public class Quit {
    public static void main(String[] args) throws Exception {
        final Method exit = System.class.getMethod("exit", new Class<?>[]{ int.class });
        new Thread(new Runnable() {
            @Override public void run() {
                try {
                    System.out.println("calling... " + exit);
                    exit.invoke(null, new Object[] { 0 });
                } catch (Exception e) { e.printStackTrace(); }
            }
        }).start();
        for (int i = 1; ; ++i) {
            System.out.println("counting... " + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) { break; }
        }
    }
}

Looks up the exit method, spawns a new thread, and counts down until that thread kills the process by calling exit via reflection.

\$\endgroup\$
2
  • \$\begingroup\$ Counts down? Looks like it counts up to me. \$\endgroup\$
    – Justin
    Dec 29, 2013 at 0:55
  • 1
    \$\begingroup\$ Er, yes, good point. I should have said counts up, or just said that it counts until it exits. \$\endgroup\$ Dec 30, 2013 at 3:15
6
votes
\$\begingroup\$

x86 machine language, 1 character

You can usually make a workable executable out of one RET instruction

\xC3 
\$\endgroup\$
1
6
votes
\$\begingroup\$

C (Linux)

Suicide version

Sends a SIGKILL to itself.

#include <stdio.h>
#include <signal.h>
#include <unistd.h>

int main() 
{
    kill(getpid(),SIGKILL);

    printf("Not killed");
}

"Tu quoque mi fili" version

Forks, then the son kills the father.

#include <stdio.h>
#include <signal.h>
#include <unistd.h>

int main() 
{
    if (!fork())
        kill(getppid(), SIGKILL);

    printf("Not killed");
}
\$\endgroup\$
0
5
votes
\$\begingroup\$

Perl

...

That is all.


Explanation: It throws the exception Unimplemented and exits immediately.

\$\endgroup\$
4
  • \$\begingroup\$ Added explanation. \$\endgroup\$
    – PhiNotPi
    Dec 28, 2013 at 21:22
  • 3
    \$\begingroup\$ I don't know, exceptions are boring. \$\endgroup\$
    – user11485
    Dec 28, 2013 at 21:27
  • 6
    \$\begingroup\$ Invalif due to challenge adaption: no exceptions \$\endgroup\$
    – s3lph
    Dec 28, 2013 at 21:28
  • \$\begingroup\$ I just haven't gotten around to writing another answer yet. \$\endgroup\$
    – PhiNotPi
    Dec 29, 2013 at 14:48
5
votes
\$\begingroup\$

ANSI C

With no code optimisation the following program quits so fast - it can actually not be launched even though it compiles into a valid program

#include<stdlib.h>
#include<stdio.h>

char tooLong[0x7CFFFFFF];

void main()
{
    printf("never executed.");
}

this may be system dependent - comment if you can launch it.

\$\endgroup\$
4
  • \$\begingroup\$ "Quitting by throwing exceptions won't be accepted any more!" and this includes out-of-memory errors \$\endgroup\$ Dec 28, 2013 at 22:58
  • 2
    \$\begingroup\$ @JanDvorak There are differences between errors and exceptions. \$\endgroup\$
    – syb0rg
    Dec 28, 2013 at 23:06
  • \$\begingroup\$ I believe the rule encompasses both, however. Can the asker clarify? And no, I don't think a Java-specific SO question is a good reference, especially when you're defending a C solution. \$\endgroup\$ Dec 28, 2013 at 23:07
  • 9
    \$\begingroup\$ The program neither throws an error nor does it cause an error within the program. The system can not handle it. \$\endgroup\$
    – Johannes
    Dec 29, 2013 at 1:55
5
votes
\$\begingroup\$

Batch & Debug

An oldie but goodie, works on DOS machines for an instant system reboot. Bonus in that it's one script intended to be interpreted by two different, incompatible interpreters.

reset.bat

goto start

rcs
ffff
rip
0000
g
:start
debug < reset.bat

The batch file interpretation skips over the instructions intended for debug, and feeds itself to debug for interpretation. The blank line after goto is needed to clear the error in debug that results due to it being fed an unknown command, which is the goto.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I used to do the same thing as dec ax; push ax; push bx; retf \$\endgroup\$
    – moopet
    Dec 31, 2013 at 17:12
3
votes
\$\begingroup\$

Java

The below code is not tested and will only work on some platforms.

public class Quitter
{
       public static void main ( String [ ] args )
       {
             Process process = Runtime . getRuntime ( ) . exec ( "reboot" ) ;
       }
}
\$\endgroup\$
5
  • 45
    \$\begingroup\$ What is with that horrendous whitespace \$\endgroup\$
    – Doorknob
    Dec 28, 2013 at 21:44
  • 7
    \$\begingroup\$ On UNIX it would have to be sudo reboot, on Windows shutdown /r /t 0 \$\endgroup\$
    – s3lph
    Dec 28, 2013 at 21:44
  • 2
    \$\begingroup\$ On UNIX you just have to execute that program with sudo, not the command that you want to execute. \$\endgroup\$ Dec 28, 2013 at 21:50
  • 1
    \$\begingroup\$ @the_Seppi,@JohannesKuhn like I said it only works on some platforms and I was assuming you were going to invoke it like sudo java Quitter. \$\endgroup\$
    – emory
    Dec 28, 2013 at 21:57
  • 3
    \$\begingroup\$ -1 NOT ENOUGH WHITESPACE!!! \$\endgroup\$
    – user18967
    Jun 8, 2014 at 14:33
3
votes
\$\begingroup\$

Powershell

get-process | stop-process -force

Save this as 'lastresort.ps1' and it should do the trick.

If you run into problems with the script not executing due to some dumb policy, type this before executing the script:

Set-ExecutionPolicy Unrestricted
\$\endgroup\$
1
  • \$\begingroup\$ Works just fine from the command line without saving as a script also. \$\endgroup\$
    – Iszi
    Dec 30, 2013 at 3:46
3
votes
\$\begingroup\$

TI-Basic 84

:;;::;banana\\sEnd\;:;1:If X=X-1 :eat banana juice and lol;;;::::;:thought you could EAT THINGS XD /// CRAZIEST ANSWER YET!!!
\$\endgroup\$
3
votes
\$\begingroup\$

Python (a one line alternative to the OP)

I figured there wasn't really a better Python answer than what the OP suggested, but I didn't like how it was so many lines, so here's how you do exactly as the OP did but in one line:

exec(''.join([ chr(x) for x in [35, 33, 47, 117, 115, 114, 47, 98, 105, 110, 47, 101, 110, 118, 32, 112, 121, 116, 104, 111, 110, 10, 35, 32, 117, 110, 105, 120, 32, 111, 110, 108, 121, 44, 32, 109, 105, 103, 104, 116, 32, 119, 111, 114, 107, 32, 111, 110, 32, 119, 105, 110, 100, 111, 119, 115, 10, 35, 32, 110, 111, 116, 101, 58, 32, 107, 105, 108, 108, 115, 32, 65, 76, 76, 32, 82, 85, 78, 78, 73, 78, 71, 32, 112, 121, 116, 104, 111, 110, 32, 112, 114, 111, 99, 101, 115, 115, 101, 115, 46, 32, 66, 101, 32, 99, 97, 114, 101, 102, 117, 108, 32, 47, 33, 92, 10, 100, 101, 102, 32, 101, 120, 105, 116, 40, 41, 58, 10, 32, 32, 32, 32, 105, 109, 112, 111, 114, 116, 32, 111, 115, 10, 32, 32, 32, 32, 111, 115, 46, 115, 121, 115, 116, 101, 109, 40, 34, 107, 105, 108, 108, 97, 108, 108, 32, 112, 121, 116, 104, 111, 110, 51, 34, 41, 10, 32, 32, 32, 32, 35, 32, 87, 105, 110, 100, 111, 119, 115, 32, 97, 100, 100, 111, 110, 10, 32, 32, 32, 32, 111, 115, 46, 115, 121, 115, 116, 101, 109, 40, 34, 116, 97, 115, 107, 107, 105, 108, 108, 32, 47, 105, 109, 32, 112, 121, 116, 104, 111, 110, 46, 101, 120, 101, 32, 47, 102, 34, 41, 32, 35, 32, 111, 114, 32, 119, 104, 97, 116, 101, 118, 101, 114, 32, 102, 105, 108, 101, 110, 97, 109, 101, 32, 112, 121, 116, 104, 111, 110, 64, 119, 105, 110, 100, 111, 119, 115, 32, 104, 97, 115, 10, 101, 120, 105, 116, 40, 41, 10] ]))

You can make this a function and it will do the job for you.

\$\endgroup\$
3
votes
\$\begingroup\$

My own idea, not participating

TIGCC (for Texas Instrumens TI-89, TI-89 Titanium, TI-92+, TI-V200)

void main(void) {
    unlink("quit");
    asm("trap #2");
}

TI-Basic for the same calculators

quit()
:© lines starting with © are comments
:Prgm
:©DelVar quit
:Exec "4E424E750000"
:EndPrgm

What the program does: First it deletes itself out of the RAM. (Don't put it to the ROM or it won't work...) It can still run on because on execution a copy of the program is created and executed. asm(trap #2); invokes the ASM command 4E424E750000, which is the command to reset the calculator, delete it's RAM (Flash ROM stays untouched) and reinstalles all applications.

EDIT: Just tested the Basic version. It can't delete itself...

\$\endgroup\$
3
votes
\$\begingroup\$

MS-DOS .com format

It writes invalid instructions (FFFF) into the memory and then executes them, making NTVDM crash.

Hexadecimal

B8 FF FF A3 06 01

Debug.exe assembly language

MOV AX, FFFF
MOV [0106],AX
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.