The code looks something like this
int main() {
printf("Starting process id is %d\t", getpid());
if (fork() == 0) {
fork();
} else {
fork();
fork();
exit(0);
}
printf("%d\t", getpid());
}
For the most part the outputs behave as expected where tracing. That is if we start with id n
we get n+1
and n+5
being printed. However when I print the starting process id it gets printed 5 times and I am not sure why. Any help would be appreciated
Output from a sample run looks like this
Starting process id is 27252 pc@pc-VirtualBox:~/Desktop$ Starting porcess id is 27252 Starting porcess id is 27252 Starting porcess id is 27252 27253 Starting porcess id is 27252 Starting process id is 27252 27257
However I would have expected to see
Staring process id is 27252 27253 27257