Im having some trouble in forking. All i want to do is to create a child process and under the child process i need to create a grand child..here's my code
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main(int argc, char *argcv[])
{
int val;
val =fork();
if(val==0){
printf("Child process running\n");
printf("Child:%d PID:%d\n",val,getpid());
val=fork();
if(val==0){
printf("Grand child created\n");
printf("Grand child:%d PID:%d\n",val,getpid());
}
}
else if(val>0){
printf("Parent process running\n");
printf("Parent:%d PID:%d\n",val,getpid());
}
else{
printf("Error\n");
}
return 0;
}
Once i run the program the grand child and the child process has a different PID. what am i doing wrong? thanks guy