91

If you run a .bat or .cmd file with %0|%0 inside, your computer starts to use a lot of memory and after several minutes, is restarted. Why does this code block your Windows? And what does this code programmatically do? Could it be considered a "bug"?

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Doon
  • 3,339
  • 5
  • 25
  • 31

5 Answers5

161

This is the Windows version of a fork bomb.

%0 is the name of the currently executing batch file. A batch file that contains just this line:

%0|%0

Is going to recursively execute itself forever, quickly creating many processes and slowing the system down.

This is not a bug in windows, it is just a very stupid thing to do in a batch file.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • 9
    Why does %0|%0 break windows, but %0 does not? – Pavel Dec 01 '16 at 01:02
  • 21
    @Pavel: What a `.bat` file does is: read instruction, at the end of file terminate. If you run %0: Process 1: starts, run %0 (thus create process 2); then die Process 2: starts, run %0 (thus create process 3); then die [...] you alway have at most 2 process running because the creator will die. The point of fork bomb is to create 2 version. Thus P1 create 2 process (1' and 1"), those two process will create, each, 2 (thus 4), going exponential. – pltrdy Jan 04 '17 at 11:21
40

This is known as a fork bomb. It keeps splitting itself until there is no option but to restart the system. http://en.wikipedia.org/wiki/Fork_bomb

Harrison Dyer
  • 409
  • 4
  • 2
33

What it is:

%0|%0 is a fork bomb. It will spawn another process using a pipe | which runs a copy of the same program asynchronously. This hogs the CPU and memory, slowing down the system to a near-halt (or even crash the system).

How this works:

%0 refers to the command used to run the current program. For example, script.bat

A pipe | symbol will make the output or result of the first command sequence as the input for the second command sequence. In the case of a fork bomb, there is no output, so it will simply run the second command sequence without any input.

Expanding the example, %0|%0 could mean script.bat|script.bat. This runs itself again, but also creating another process to run the same program again (with no input).

Community
  • 1
  • 1
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
11

%0 will never end, but it never creates more than one process because it instantly transfers control to the 2nd batch script (which happens to be itself).

But a Windows pipe creates a new process for each side of the pipe, in addition to the parent process. The parent process can't finish until each side of the pipe terminates. So the main program with a simple pipe will have 3 processes. You can see how the bomb quickly get's out of control if each side of the pipe recursively calls the parent batch!

dbenham
  • 127,446
  • 28
  • 251
  • 390
  • 1
    How is the second part of the pipe called if the first recursive call never returns? – mowwwalker Jan 21 '12 at 01:02
  • 3
    The two sides are run asynchronously – dbenham Jan 21 '12 at 01:05
  • 2
    I was told that the pipeline calls the second half with the return of the first half: http://www.csie.ntu.edu.tw/~r92092/ref/win32/win32scripting.html#Win32Scripting-Command-Redirection-And-Pipelines – mowwwalker Jan 21 '12 at 01:10
  • 3
    There is good info about the asynchronous nature of Windows pipes here: http://stackoverflow.com/a/8194279/1012053 – dbenham Jan 21 '12 at 01:13
6

It's a logic bomb, it keeps recreating itself and takes up all your CPU resources. It overloads your computer with too many processes and it forces it to shut down. If you make a batch file with this in it and start it you can end it using taskmgr. You have to do this pretty quickly or your computer will be too slow to do anything.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Edward
  • 77
  • 1
  • 1