3 ms·
while(1) {fork()}; is "better", as the version you mention will quit as soon as it is able to fork a new process.
by TheLoneWolfling 12y ago
while(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.