I have some C code using fork but I don't understand how it works
int hijo,i,N; int main(int argc, char*argv[]){ N=atoi(argv[1]); for(i=0;i<N;i++) if((hijo=fork())>0)break; } Why does this program create only one child process of the previously created process and doesn't create a process for each of the processes that exist before do the fork?
N? 2: It's unclear what you're asking; are you wondering why the children don't fork too?printf()traces that help understand which process execute which part of code.pid=fork(); if(pid==0) {/*Child code*/} else{ wait()}this last wait() is important to not leave any zombie child because childs would be running on background forever if the child program does not end.