3 ms·
Actually, after looking at it again, I believe your code is at risk of deadlocking. If the program under test produces enough output to fill the stdout or stde
by kd5bjo 9y ago
Actually, after looking at it again, I believe your code is at risk of deadlocking. If the program under test produces enough output to fill the stdout or stderr pipe buffer, the next write will block until your program reads some data out of it.
That can only happen once you've finished writing everything to the stdin pipe, which may be full because the program under test has stopped reading from it (due to blocking on its write call).
To avoid this, you need to process all three file descriptors in one loop using something like select() or poll() to work with whichever descriptor can make progress. Or, let a completely separate process (like the shell) handle the downstream file descriptors for you.