I have a process that forks a child process that then runs a few syscalls. There is the possibility that the syscalls the child runs could cause it to block while it processes the calls, but I don't want the parent to wait. Further, I want the parent process to allow the child to run for a certain period of time and if the child is still blocked after a specified number of seconds, the parent will kill off the child.
I am using waitpid(pid, &status, WNOHANG) to have the parent process not wait for the child. So I'm not sure what to do next. Do I keep looping back to waitpid() until either the child completes it's tasks and returns status or until the timeout value is reached or how do I loop over checking status of the child while evaluating the timeout?
I looked over the waitpid man page but didn't see