fork in C++

R

Ramesh

Hi All!

I have written a progarm which will create 10 child processes ( by
fork) to execure a method simuleneously; But the the child will do
database updates. In the parent I need database success/failure update
counts done by each child. For that I declared global two arrays to
assign in the child processes; But once the child process exists then
global variables coming to original values, the child updated values
are not reflecting once child existed; I tried even with static
member variables also;

two static member variable are declared:

static int fList[10] ;
static int sList[10] ;

Static def:

int C_SMSSvcRetroExpireProcess::sList[] = { 0 };
int C_SMSSvcRetroExpireProcess::fList[] = { 0 };

Fork:
for ( index = 0; index < MAX_PROCESSES && (pid = fork()) !
= 0 ; index++ )
{
// Spawned a number of child processes to be executed
// simultaneously.
........
}
// child process
if ( pid == 0 )
{
// this is the method to be called, which will update
database inturn
smsRetroExprEligibleSvcSuccessCount[index] =
processRetroRecs ( smsSvcDeactvVCltn,
startRecCount,
endRecCount,
fileSeqNbr++,
retroActiveAutoExprDays,
_smsRetroProcessDir,
recsEligibleForUpdate,
index,
childRetCode);

TRACE_BEGIN( APPLICATION ) << "After sList[" << index
<< "]="<< sList[index] << TRACE_END;
TRACE_BEGIN( APPLICATION ) << "After fList[" << index
<< "]="<< fList[index] << TRACE_END;

// exit the child
_exit(childRetCode); // Up to here I am able to print
the above two statement correctly
}

In the child process code I am able print the sList, fList correctly
but once _exit(childRetCode); is executed I lost the child update
values; I tried to declare the sList, fList as global and also
static;But still I am not able track the child update values;

How to retain the fList, sList in parent above even if the childs
exited? Please give me clue... Thank a lot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Linux: using "clone3" and "waitid" 0
Communicating between processes 0
C pipe 1
tzset() locks in Linux after fork() 2
'fork' query 3
fork/exec question 6
fork() 5
fork() 27

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top