Timed wait?

Is there any way in which I can make my wait signal to wait for a specified time for child job to complete. And if that time is over, the program gets out of the wait signal to process other things

Is there any way in which I can make my wait signal to wait for a specified time for child job to complete. And if that time is over, the program gets out of the wait signal to process other things, even if the child job is not complete

Please do not duplicate your posts. That is against the rules.

Now on to your post. There is no call in Linux which does something like that. Win32 API's has something on those lines viz WaitForMultipleObjects.

You can try to simulate something like that. After forking the child, the parent can try sleeping for some amount of time.

You may also want to use the WNOHANG flag so that the execution is not suspended if the child's status is not available immediately.

You could combine both of vino's suggestions and have a loop where you wait with WNOHANG and then sleep for a second. Have a counter to achieve your timeout condition.

This might be wasteful of CPU though.

Or set an alarm then do a blocking wait.

If you did not know, all wait does, if there are no zombies to reap, is wait for a SIGCLD signal from one of it's children, You could wait for that signal explicitly.