-1

I am trying to make a fork bomb which closes itself as soon as the flash drive on which it is stored is removed. This is my code so far:

:start
start %0
IF EXIST E:\forkbomb.bat goto start

For some reason it stays open even once the flash drive is removed, why does the condition not become false once the flash drive is no longer inserted and cause the program to exit? Thanks!

nosyarg
  • 156
  • 9

2 Answers2

1

Swap line 1 and 2 ;)

It won't technically be a fork bomb anymore but it will still create many windows who will all banish themselves as soon as the flash drive disappears.

Edit, did some further thinking, and you also need another IF.

IF EXIST E:\forkbomb.bat start %0
:start
IF EXIST E:\forkbomb.bat goto start

In fact you could even try your luck with the original fork bomb design.

Conceptually it didn’t work for you probably because every instance had to be past the highlighted line below at the instance the drive was removed:

:start
start %0   <<<< this line
IF EXIST E:\forkbomb.bat goto start

Because if even one of the instances is before the start then it will keep creating new instances (without the loop). So essentially your fork bomb gets degenerated into a situation where each window creates exactly one new window.

tl;dr without further ado here is my amended solution

:begin
IF NOT EXIST E:/forkbomb.bat goto end
start %0
goto begin
:end

Now that is a full fork bomb and when the drive is removed it will clean up itself as fast as possible.

Cheers

Samie Bencherif
  • 1,285
  • 12
  • 27
-2

A forkbomb will normally render your system inoperatable in the means of seconds. So you would only have a few seconds (if not less) to remove the USB drive. When too many processes are spawned the disconnect will probably come very late, as other processes take the CPU and the stick will still be "plugged in". Even when the file is not there, there is damn much in the queue that even then new processes will keep spawning, for which the condition was already met.

Also, sorry for this insult, but what you are trying is just plain stupid. Do you really understand how a forkbomb works? Because you are talking of "the program" (you should be speaking of "the many many many many many processes). Simplified, a fork bomb is just a self-reproducing process that again will reproduce, and so on. You junk your system memory damn fast!

Nidhoegger
  • 4,973
  • 4
  • 36
  • 81
  • great, so when I remove the USB drive (I do it fairly quickly) I am able to close the windows all with repeated alt+f4, and there are not terribly many of them. I just want to have every process close itself without me needing to close several hundred windows. I am obviously running this on an old machine which, if it crashes, does not mean the end of the world, so I would certainly appreciate an explanation of why my code is not working. – nosyarg May 11 '15 at 18:03