Yes, it is. The wait() function, or waitpid(), will cause the parent program to wait until the child process terminates (and thus, makes its status known).
It is best used within an if block, so that the waitpid() call is not accidentally called by the child process (which would be messy at worst, and uncompileable at best
)
Code:
#include <sys/types.h>
#include <sys/wait.h>
int main() {
int status;
pid_t id = -1;
pid_t child_id;
id = fork();
if(id < 0) { //problems with the fork call
return 1;
}
if(id == 0) { //this will be executed by the child process
// do stuff
return 0;
}
if (id != 0) { //this will be executed by the parent process
//do stuff
//wait for the child process to exit
child_id = wait (&status);
//child_id contains numeric exit status of child process
//status contains exit status information of child process
}
//only parent running now
exit 0;
}
You can get more dynamic information using semaphores and message passing between the child & parent processes. However, if you're not familiar with that a google search on those topics would probably be more useful than me trying to explain them here (and it's been awhile since I used them, so I couldn't do a very good job anyhow).
G'luck!