3

There's a shell script floating around the Internet that looks like this:

:(){ :|: & };:

Basically this shell script just creates a function that calls itself, leading to infinite recursion. Apparently this is a fork bomb and it will keep going until it uses up resources and crashes your system.

My question is, wouldn't this script cause a stack overflow and cause the shell to segfault before it consumes all the system's resources? How does this work exactly?

user628544
  • 1,565
  • 4
    See http://stackoverflow.com/a/515923 for a really clear answer, which includes reference to ulimit and /etc/security/limits.conf. Bottom line is that the possibility of a stack overflow gets swamped by the actual process table overflow. – Chris Davies Sep 07 '16 at 13:06

1 Answers1

0

In modern linux versions , if you run that code in a bash , it will not crash your system. What it does is to abouse the 'fork' system call . The '&' from your fucntion means it to execute in background , and when it try to do so , it use the fork() system call .It will fork so many times that the fork will be unavailable so you will not be able to start new applications ,because that need to fork too, but the aplications and you have already running will be just fine.

CGeorgian
  • 101