When I try to run this code on my terminal, I get the output "hello from X process" after my prompt:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
void forkexample()
{
pid_t pidTo;
int status = 0;
int x = 1;
if (fork() == 0){
printf("hello from child process %d\n",getpid());
}
else{
printf("hello from the parent process %d\n",getpid());
}
}
int main()
{
forkexample();
exit(0);
}
My question is why am I getting the "hello from child process" after the prompt?