The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-07-2001
Registered User
 

Join Date: Oct 2001
Posts: 1
Question Reference Variables To A Child Process Created With Fork

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
Reply With Quote
Forum Sponsor
  #2  
Old 10-07-2001
rwb1959's Avatar
Registered User
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
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
Reply With Quote
  #3  
Old 10-07-2001
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,441
Sounds like a homework problem to me...... Let's not answer homework problems, if we can avoid it. Thanks.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0