954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to fork a grandchild process

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 #include #include

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

herms14
Light Poster
47 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

I think they should have different pid's

kinger29
Light Poster
36 posts since Mar 2008
Reputation Points: 11
Solved Threads: 2
 
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

herms14
Light Poster
47 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You