c - Fork system call not exiting -
i've run following code :
#include <stdio.h> #include <sys/types.h> int main() { fork(); fork(); fork(); printf("hello\n"); return 0; }
after printing word "hello" 8 times, program not exiting. reason behind this?
this accidentally interesting way calculate 2^3. first fork makes second fork happen twice , each make third fork happen twice , 8 children run printf! 8 processes exit, prompt lost in noise.
as commenters implied, fundamentally misunderstanding fork() , doing. along way made interesting toy, bravo!
Comments
Post a Comment