Quote:
Originally Posted by smoothdogg00
I am starting a process and calling waitpid(pid, status, WNOHANG), which allows it to continuously check to see if the process is complete. Now, the problem I am facing is printing a message when a child process completes.
Is there any way to use waitpid() to report back when a process completes?
|
I don't understand what the problem is. What you're asking for is exactly what waitpid() does: after
waitpid(pid, status, WNOHANG), the variable
status can tell you if the process (with
pid) stopped, dumped core, or exited.
Please read "man waitpid" for more information on how to check if it exited.
<edit>
I noted that you call waitpid() passing the variable
status without taking it address with
&. This is not necessarily a problem if
status is a pointer to an int, e.g. something like:
Code:
int st;
int *status;
status = &st;
waitpid(pid, status, WNOHANG);
If you have something like the above, it's OK. But make sure you check
stat instead of
status to see if the process exited.
</edit>