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]);
for(i=0; i<num; i++){
if(wait(NULL) == -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

10 Years
Discussion Span
Last Post by Salem

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.