You can read from the pipe until it becomes empty. This will cleanse it effectively.
Before you attempt this bold feat, call fcntl(mypipe, F_SETFL, O_NONBLOCK) (I don't know the shell script equivalent) to read when the pool is empty, do not hang your program.
Borealid
source share