Only solution which works for now is to redirect stderr to stdout, and read stdout on thread. Code without thread or with read() or read(n) (when n>1) can block. Code with select() and read(1) works, but it is very slow.