| | |
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
Once i run the program the grand child and the child process has a different PID. what am i doing wrong? thanks guy
•
•
•
•
#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;
}
Last edited by herms14; Aug 18th, 2009 at 9:27 pm.
![]() |
Similar Threads
- get data from child process through pipe (C++)
- Fork() (C)
- creating a child process using c program (C)
- Using fork() help. (C)
- fork, exec, and pipes (C++)
- Simple Fork code (C)
- ambiguous part 3 (C)
- Launching an application from a thread (C++)
Other Threads in the C Forum
- Previous Thread: can't get fopen to work
- Next Thread: File Help
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks bash binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram ide inches include infiniteloop initialization input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation owf pdf pointer pointers posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming standard strchr string suggestions systemcall test testautomation testing threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi





