• Voroxpete@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    47
    ·
    edit-2
    2 days ago

    For those curious as to how this works…

    Part one is ‘:()’. This creates a new function named ‘:’. That’s because we start with the name, ‘:’, then the open and closed brackets (this is where you put any inputs the function expects), which is the shell syntax for creating a function.

    Part two is ’ ::& '. This creates the content of the function. The curly braces define the beginning and end of the content. Everything inside them is the function itself. The first part of the actual function is ‘:’, so it’s literally running itself. On its own this would just mean it runs forever doing nothing. But then we have a ‘|’ (pipe) character; this takes the output of the previous command and feeds it into the input of the next one. The next command is another ‘:’, so it’s calling itself again. What this means is that every time ‘:’ gets called, it calls itself twice. The last part of the function is an ‘&’ character so that the second call of the function gets run in the background. So now every time this loop runs we create two copies of our program (yes, this is a program, just a very simple one), which each create two copies, and so on.

    Finally, we have the last characters / commands. The first is a ‘;’ (semi-colon) which means “After doing that, do this.” That allows us to continue on to the last command, which is ‘:’ again. So, having defined our endlessly multiplying function, we finally run it for the first time, setting off the entire self-replicating loop. Endless copies of this tiny program will run themselves infinitely, eating up all our RAM and CPU time and crashing the PC.

    In practice, modern Linux systems have an upper limit on the number of processes that can run, so if your system resources are high enough it won’t crash, just struggle.