This is not waiting for ping to complete. Rather, ping waits until the stdout buffer is full before writing anything. The only ways to avoid this are pseudo-ttys. Either you must abandon popen and write code to start the ping child process yourself, and use pseudo-tty to communicate (this is easy with the non-standard, but widely available forkpty function), or you can write a wrapper program that starts ping through pseudo- pty and captures the output signal and writes it without buffering to stdout .
source share