1

I have a very fragmentary understanding of shells, subshells, functions, background processes and therefore I am insecure in understanding how this fork bomb works in detail,

However I tell you how what I know:

  • :() Here the colon is simply an unusually looking function name
  • {...} Here is described what the function is doing
  • {:()} Here the function calls the next iteration of itself
  • {:()&} Here the function calls itself and puts the next iteration of itself into the background of the shell
  • ...;: The last colon is the starting point of the function's actual execution, what is before is just its definition

So, my basic understanding is, it is a recursive function, which works like a spawning machine, spawning copies of itself until the point the system can not proliferate social wellfare anymore.

But, I do not really understand in a visually way what is happening step by step.

For instance

  • :()|:()& Why are both function callings combined through a pipe symbol?
  • Is the fork bomb spawning in a linear fashion, a constant number of processes per time unit or is it more abombically exponential like the two function calls suggest.

Could some one provide additionally a visual step by step comic strip of the spawning process, no matter how sloppy?

sharkant
  • 3,710
  • 1
    While it is a pipe symbol/character it isnt a pipe it is an or in this case IIRC – ivanivan May 12 '17 at 21:13
  • Definitely it is, but I wanted to risk a double explanation because I hoped to get a visual answer , a diagram, instead of an answer which leaves some obscurity unexplained, at least to the people with less knowledge. – sharkant May 12 '17 at 21:14
  • 1
    @ivanivan no, it is a pipe. That’s how the bomb scales: both sides of the pipe start in parallel... – Stephen Kitt May 12 '17 at 21:18
  • does it have a special name, when one function is piped into another or is there no difference when comparing an ordinary command pipes into another command? – sharkant May 12 '17 at 21:52
  • https://explainshell.com/explain?cmd=%3A%28%29%7B+%3A+%7C+%3A%26+%7D%3B+%3A – Tom M Sep 20 '18 at 08:12

1 Answers1

1

Here’s a visual explanation; sorry it’s not a comic, but it should illustrate:

  • step 1: run the function

    :
    
  • step 2: the function runs two copies of itself, using a pipe to start both in parallel (the backgrounding operator doesn’t really seem to matter here, as described in the answer to How does a fork bomb work?)

    (:|:)
    

    (I’m using parentheses here just for clarity)

  • step 3: repeat the process for each :

    ((:|:)|(:|:))
    
  • and so it goes on

    (((:|:)|(:|:))|((:|:)|(:|:)))
    

    and on, replacing each : with (:|:) at every step

    ((((:|:)|(:|:))|((:|:)|(:|:)))|(((:|:)|(:|:))|((:|:)|(:|:))))
    
    (((((:|:)|(:|:))|((:|:)|(:|:)))|(((:|:)|(:|:))|((:|:)|(:|:))))|((((:|:)|(:|:))|((:|:)|(:|:)))|(((:|:)|(:|:))|((:|:)|(:|:)))))
    
    ((((((:|:)|(:|:))|((:|:)|(:|:)))|(((:|:)|(:|:))|((:|:)|(:|:))))|((((:|:)|(:|:))|((:|:)|(:|:)))|(((:|:)|(:|:))|((:|:)|(:|:)))))|(((((:|:)|(:|:))|((:|:)|(:|:)))|(((:|:)|(:|:))|((:|:)|(:|:))))|((((:|:)|(:|:))|((:|:)|(:|:)))|(((:|:)|(:|:))|((:|:)|(:|:))))))
    

etc. until the system runs out of resources (by which time it will have become very unresponsive indeed).

Stephen Kitt
  • 434,908