arun11299 / cpp-subprocess

Subprocessing with modern C++
Other
449 stars 90 forks source link

Busy looping when waiting for subprocess to finish #70

Open landersson opened 2 years ago

landersson commented 2 years ago

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?

bcov77 commented 2 years ago

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