cpp-subprocess icon indicating copy to clipboard operation
cpp-subprocess copied to clipboard

Busy looping when waiting for subprocess to finish

Open landersson opened this issue 3 years ago • 1 comments

Hi,

I just noticed that my program is busy-looping and thus using up a lot of CPU resources while waiting for a subprocess to finish. I'm using the Popen class. The root cause seems to be that waitpid() is used with the WNOHANG option in the util::wait_for_child_exit(int pid) function.

Why is WNOHANG being used? Is there a way to avoid busy-looping while waiting for a subprocess to finish?

landersson avatar Aug 26 '21 07:08 landersson

Better to add a usleep() to wait_for_child_exit() so the other issue about timeouts can be dealt with.

bcov77 avatar Jan 27 '22 20:01 bcov77