Why doesn't the program end? The child hangs after printing what it has to print. If the parent process slept instead of the child, It would have worked, but why is that? I have also tried calling exit at the end of each process, but with the same result. Do I always have to wait for the child to finish?
int main(){
int pid = fork();
char s[100] = "Hello";
if(pid > 0){
printf("FIRST PRINT IN PARENT: %s\n", s);
strcat(s, " - PARENT");
printf("SECOND PRINT IN PARENT: %s\n", s);
}
else if(pid == 0){
printf("IMMEDIATELY IN CHILD: %s\n", s);
sleep(2);
printf("AFTER 2 SCONDS IN CHILD: %s\n", s);
}
return 0;
}