Code:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
pid_t pid;
char *message;
int n;
printf(“fork program starting\n”);
pid = fork();
switch(pid)
{
case -1:
perror(“fork failed”);
exit(1);
case 0:
message = “This is the child”;
n = 5;
break;
default:
message = “This is the parent”;
n = 3;
break;
}
for(; n > 0; n--) {
puts(message);
sleep(1);
}
exit(0);
}
As you can see from code, the parent process finishes before the child. In this case, the child process should be terminated too, but it's still running. I checked with htop and it seems that when the father-process finishes, the child "gets" another parent:init. What I don't understand is why the child process doesn't terminate simultaneously with the father( Yes, I know what's a Program Counter

)
LE: Thanks, introuble