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

Easy to test out to. In C:

  #include <unistd.h>
  
  int main(void)
  {
         while(1) {
                 fork();
         }
  }


Haha too cruel. I remember in one of my early college CS classes the professor told us about fork bombs and wasn't sure if they still worked on the Sun Fire servers we were using. About 5 minutes later someone piped up and confirmed that yep they still worked at bringing the server down. :)


That's why user accounts should have appropriate resource limits set per user.


while(fork()) {};


while(1) {fork()}; is "better", as the version you mention will quit as soon as it is able to fork a new process.


Nope, it won't quit. In failure fork returns -1, what's still true...

But the forked processes will quit as soon as they are created. Thus, it won't work anyway.


Parent said as soon as it is able to fork a new process, which still isn't quite right (it's the child that quits, as you say) but not the error you seem to be responding to.


He didn't say this when I replied.


Ah, do you remember what it said?


I got it swapped around initially:

"while(1) {fork()}; is "better", as the version you mention will quit as soon as it is not able to fork a new process."

or something similar


Gotcha.


Will it quit? A failed fork() will return -1, which is non-zero thus true in a boolean context. The while(fork()) {...} will run.


But it will stop when fork returns 0, i.e. in the child processes, making it non-exponential.




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

Search: