![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum 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 |
| Problems with child comunicating with parent on fork() | Zarnick | High Level Programming | 8 | 05-06-2008 09:35 AM |
| fork() and child processes | green_dot | Shell Programming and Scripting | 1 | 03-19-2008 05:49 AM |
| fork() and child processes | green_dot | High Level Programming | 0 | 03-19-2008 05:44 AM |
| fork() with su (child with other user) | heck | High Level Programming | 1 | 01-12-2007 06:58 AM |
| the scop of variables in child process | netman | High Level Programming | 5 | 01-06-2006 09:22 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi!
IN THE FOLLOWING PROGRAM THE VALUE OF j REMAINS UNCHANGED . WHY ? IF I WANT A VARIABLE VALUE TO CHANGE LIKE THIS , IS THERE ANY WAY TO DO IT ? Or do we have to use shared memory variables? main() { int return_pid, i, total; int j=1; total = TOTALRECS+1; for (i=0; i<NUMPROCESSES; i++) if (fork() == 0) child_code (i,total,&j); for (i=0; i<NUMPROCESSES; i++) return_pid = wait(0); printf ("value of J <%d>\n", j); }
__________________
AJAY BHATIA |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
The short answer... yes, you should probably
use shared memory. Once you fork(), you get a new process with it's own stack and heap space (among other things). BTW, I hope your code doesn't really look like that |
|
#3
|
||||
|
||||
|
Sounds like a homework problem to me...... Let's not answer homework problems, if we can avoid it. Thanks.
|
||||
| Google The UNIX and Linux Forums |