I know that it can be either of these. But I always see that the parent executes first on my LINUX terminal.
- I used the same code on two different machine, one use kali Linux and the other Ubuntu , I got the same result.
- I searched for that and I got nothing.
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
int main(){
int id = fork();
if(id == -1) {
printf("error!");
return 1;
}
if(id == 0){
printf("I'm the child\n");
printf("child\n");
return 2;
}else{
printf("I'm the parent\n");
wait(NULL);
printf("child has terminated\n");
return 3;
}
return 0;
}