3 ms·
Could you explain how this works?
by doetoe 3y ago
Could you explain how this works?
- system33- 3y agoA function called ':' is defined. In its body, it calls itself twice at the same time (':|:') (piping the output of the first call into the second, which doesn't do anything useful) and sends these calls to the background ('&'). After function ':' is finished being defined, it is called. The first call spawns two clones. Each of those spawn two more. Etc.
- doetoe 3y agoGreat, thanks!
- xav0989 3y ago:() defines a new function called : { :|:& } is the body of the function, where we call the : function recursively, piping (|) its output to another call to :, then backgrounding the whole thing (&) ; indicate the end of a statement and the start of a new one : and finally the last : calls the function we defined to start the chain Essentially each time the function is ran, it creates 2 new copies of itself, which each create 2 copies of themselves, etc. until your OS stops responding and crashes. Nowadays many shells recognize this particular fork bomb and refuse to execute it
- _flux 3y ago> Nowadays many shells recognize this particular fork bomb and refuse to execute it Nice try! Though, do they really? I quickly checked if I would find something like this in bash, zsh or tcsh and failed, but I only spent a minute or so..
- sva_ 3y agoWell I can experimentally confirm that it works on zsh/alacritty ;)
- deleted 3y ago[deleted]