![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| fork() help | alexicopax | High Level Programming | 3 | 03-08-2007 12:08 AM |
| shm sem fork etc... Please help | Dana73 | High Level Programming | 1 | 02-28-2006 04:51 AM |
| Fork or what? | crippe | High Level Programming | 0 | 03-08-2005 01:21 AM |
| fork() | MKSRaja | High Level Programming | 2 | 02-07-2005 07:55 AM |
| Fork | Deepali | UNIX for Dummies Questions & Answers | 5 | 08-26-2001 05:14 PM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
hi all
About this code for (i = 1; i < n; i++) if ((childpid = fork()) <= 0) break; I really can't understand the output . and the way fork () return the value . how about the process Id ,the child process Id and the parent ID in this case so please answer me soon |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
Regards, |
|
|||
|
Quote:
If it all if there is any anything to be done by the child there would be only 2^(n-1)-2 child processes and 1 parent process as for validates between and 1 and < n |
|
|||
|
People try to be a little too clever with fork sometimes... whenever I use it I try to write my code like this:
Code:
pid_t pid=fork();
if(pid > 0)
{
int status;
/* This process has created an independent child process */
do_other_stuff();
/* Wait for it to finish so it doesn't become a zombie */
wait(&status);
}
if(pid == 0)
{
/* This process IS the child process! */
do_stuff();
/* Exit the program when we're done doing stuff */
exit(0);
}
else
{
/* No child process was created because of some sort of error */
}
|
|
|||
|
Quote:
pid_t pid; if( (pid=fork()) < 0 ) { /* Error Stuff */ } else if(pid == 0 ) { /* child stuff */ } else { /* parent stuff */ } the above will not mandate two if-condition checks |
|||
| Google UNIX.COM |