Hacker News new | past | comments | ask | show | jobs | submit login

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.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: