Instead of checking for a live process, check for unread data.

Add a unit test which tests proper behaviour.

Fixes #15941
Split `flag_eof` into `flag_eof_stdout` and `flag_eof_stderr`
More explicit logic