3 ms·
how about this one? int main() { fork(); printf("choo"); }
by m463 7y ago
how about this one?
int main() {
fork();
printf("choo");
}
- saagarjha 7y agoWhat's the trick (besides calling functions after fork that you shouldn't be calling?)
- oddlama 7y agoI think parent wanted to write the following: int main() { printf("choo"); fork(); } Here, "choo" can be printed twice, even though we fork after printing. This is a result from line buffering when the flush happens after the process is forked. Essentially, the output buffer is copied when forking and therefore duplicated.
- deleted 7y ago[deleted]
- m463 7y agooh yes, that's what I meant! your example and mine print the same output.