how to fork a grandchild process

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 43
Reputation: herms14 is an unknown quantity at this point 
Solved Threads: 0
herms14's Avatar
herms14 herms14 is offline Offline
Light Poster

how to fork a grandchild process

 
0
  #1
Aug 18th, 2009
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
Last edited by herms14; Aug 18th, 2009 at 9:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 31
Reputation: kinger29 is an unknown quantity at this point 
Solved Threads: 1
kinger29 kinger29 is offline Offline
Light Poster

Re: how to fork a grandchild process

 
0
  #2
Aug 18th, 2009
I think they should have different pid's
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 43
Reputation: herms14 is an unknown quantity at this point 
Solved Threads: 0
herms14's Avatar
herms14 herms14 is offline Offline
Light Poster

Re: how to fork a grandchild process

 
0
  #3
Aug 23rd, 2009
Originally Posted by kinger29 View Post
I think they should have different pid's

waht do you mean by different pid's/ should i declare a new fork? what shoud i do to create a new grand child
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC