Member Avatar for susuoi

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[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[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

Google "mmap".

Hope this helps.

> 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.