•
•
•
•
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
![]() |
•
•
Join Date: Nov 2006
Location: Tomakomai, japan
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
> 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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- kill parent and retain child process? (Java)
- the difference of using fork() and exec() with system() (C++)
- ambiguous part 3 (C)
- Does this really generate multiple instances of a UNIX process (Perl)
- fork() and wait() (C)
- Error message when starting Apache (Linux Servers and Apache)
- Launching an application from a thread (C++)
Other Threads in the C Forum
- Previous Thread: scanf discussion
- Next Thread: K&R with Visual C++.net version 2003



Linear Mode