So i just want to create a simple forking program that forks 5 children at the rate of 1 per every half second and then displays the date and time when each fork is complete.. so this is the jist of the code
int count = 1;
while(count <= 5){
int kid = fork();
if(kid == -1){
perror("error in fork");
exit(0);
} else if(!kid){
numbytes = read(sockfd, buf, sizeof(buf)-1);
buf[numbytes] = '\0';
printf("%s\n",buf);
}
count++;
usleep(500000); //create per every half second, 500000 = 0.5sec
close(sockfd);
}
return 0;
}
which I thought should be simple enough, but instead of forking 5 times it doubles after each fork.. so it forks 1 time, then 2, then 4, 8.. etc.
Help?