Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I believe either my brother or someone he knew once wrote a program that spawned lots of child processes. He did that to test a scheduler or something like that, but it got a bit out of hand and swamped a major server in endless processes. Admins weren't pleased. But also not too upset, because they approved of students experimenting. We had pretty cool admins.


A fork bomb. In shell:

    :(){ :|:& };:


Could you explain how this works?


A 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.


Great, thanks!


:() 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


> 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..


Well I can experimentally confirm that it works on zsh/alacritty ;)


Oh, lord. The sheer number of fork-bombs launched by the students in the systems programming course the week the professor introduced fork()....




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: