5 ms·
Easy to test out to. In C: #include <unistd.h> int main(void) { while(1) { fork(); } }
by runarb 12y ago
Easy to test out to. In C:
#include <unistd.h>
int main(void)
{
while(1) {
fork();
}
}
- tdicola 12y agoHaha 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. :)
- X-Istence 12y agoThat's why user accounts should have appropriate resource limits set per user.
- arthurcolle 12y agowhile(fork()) {};
- TheLoneWolfling 12y agowhile(1) {fork()}; is "better", as the version you mention will quit as soon as it is able to fork a new process.
- jimm 12y agoWill it quit? A failed fork() will return -1, which is non-zero thus true in a boolean context. The while(fork()) {...} will run.
- comex 12y agoBut it will stop when fork returns 0, i.e. in the child processes, making it non-exponential.
- marcosdumay 12y agoNope, 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.
- dllthomas 12y agoParent 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.
- marcosdumay 12y agoHe didn't say this when I replied.
- dllthomas 12y agoAh, do you remember what it said?
- TheLoneWolfling 12y agoI 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
- dllthomas 12y agoGotcha.