This question already has an answer here:
- What is %0|%0 and how does it work? 4 answers
I was looking at the fork bomb on Wikipedia, and the batch examples were:
%0|%0
OR
:here
start ''your fork bomb name''.bat
goto here
OR
:here
start %0
goto here
I understand the second two, they start another instance of themselves and then repeat, but I don't understand the first. I read that the pipeline executes the file to the right with the output of the file to the left. Why can't the fork bomb just be:
%0
I would assume that this would call itself, but then terminate instantly, but why wouldn't %0|%0
also terminate? Even though the new instance is going to keep making new instances, isn't the first done after starting the second? What makes the first one continue?
edit: Does it loop because none of the instances can terminate until their recursive call is returned? Does this mean it only ever calls the first %0
?
%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!
来源:https://stackoverflow.com/questions/8949103/batch-fork-bomb