| | |
how to fork a grandchild process
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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 |
* adobe api append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax database directory dynamic execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global gtkgcurlcompiling gtkwinlinux highest histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer license linked linkedlist linux list lowest matrix meter microsoft mqqueue multi mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scheduling segmentationfault send single socketprogramming stack standard strchr string suggestions system test testautomation testing unix urboc user whythiscodecausesegmentationfault win32api windows.h windowsapi





