LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-26-2006, 03:49 AM   #1
cynthia_thomas
LQ Newbie
 
Registered: Oct 2005
Posts: 28

Rep: Reputation: 15
waiting for a child process to finish execution in C


hi,
I have forked a child process from my main process. I want my main pgm to wait till the child finishes execution. I thought of using wait_pid() function in wait.h. But an error is comming

undefined reference to `wait_pid'.

If i am using this wait_pid(), where should i write this, before fork() or after fork()?

I want to know how to use this wait_pid() function. If there is any other way to wait for the completion of the child process please tell me that also

thanks and regards
cynthia
 
Old 05-26-2006, 04:44 AM   #2
Randux
Senior Member
 
Registered: Feb 2006
Location: Siberia
Distribution: Slackware & Slamd64. What else is there?
Posts: 1,705

Rep: Reputation: 54
man waitpid
 
Old 05-26-2006, 04:58 AM   #3
debulu
Member
 
Registered: May 2006
Location: India
Distribution: Redhat
Posts: 49

Rep: Reputation: 15
int status;
int pid=fork();
if(pid<0)
{
/*error code*/
}
else if(pid==0)
{
/*do child work here*/
}
else{
waitpid(pid,&status,0);
/* parent work */
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 08:26 AM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 01:40 AM
process and child process in java xhi Programming 4 03-28-2006 11:36 AM
Killing a child process from another child marri Programming 6 10-01-2004 08:08 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 02:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration