Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using fork and wait... 1

Status
Not open for further replies.

GooMooPunch

Programmer
Jan 26, 2004
5
US
What I'm trying to do is have my program make an execlp call and then return back to my original program...

I know that I can use fork to create another process..and that exec will replace the process that it is being called from...but i'm not sure exactly how to use fork and wait and exec together to accomplish this....
 
It looks something like this
Code:
pid_t child;
child = fork();
if ( child == 0 {
  // exec call here
} else
if ( child != -1 ) {
  // child created, now wait for it
  int status;
  waitpid( child, &status, 0 );
} else {
  // some problem, no child
  perror("Fork");
}

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top