User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,568 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,604 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1183 | Replies: 2
Reply
Join Date: Nov 2006
Location: Tomakomai, japan
Posts: 5
Reputation: susuoi is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
susuoi susuoi is offline Offline
Newbie Poster

fork->how parent refer child process results

  #1  
Oct 24th, 2007
I'm doing image processing. To make the computation faster, I found fork command. With fork command, I can make the computations run parallelI. The problem is the result only exists inside child process.
int main(int argc, char **argv){
int n, num, pid;
double hist[num][n];
for(i=0; i<num; i++){
if((pid = fork()) == 0){
//start computation, then save it to hist
for(j=0; j<n; j++) printf("%f ", hist[i][j]);
exit(0);
}
}
for(i=0; i<num; i++){
if(wait(NULL) == -1){
perror("wait");
exit(1);
}
for(j=0; j<n; j++) printf("%f ", hist[i][j]);
}
}
I can see the result from the first printf command. But I have nothing at second printf command. I want to know whether there is a way for parents to access child process.
If anybody know how to do it, please let me know.
Thanks anyway
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: fork->how parent refer child process results

  #2  
Oct 24th, 2007
Google "mmap".

Hope this helps.
Reply With Quote  
Join Date: Dec 2005
Posts: 3,834
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 23
Solved Threads: 436
Colleague
Salem's Avatar
Salem Salem is offline Offline
banned

Re: fork->how parent refer child process results

  #3  
Oct 24th, 2007
> To make the computation faster, I found fork command.
But only if you're running on a machine with more than one physical processor.
If not, you're just thrashing the scheduler.

Oh, and check out the range of "read this first" posts at the top of the forum to learn how to post code which isn't a mess. In other words, [code][/code] tags.
Hint: look at the watermark at the back of the edit window you type in.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 5:55 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC