In my HP filter, I wait for the output to flush with this code:
#include <stdio.h>
#include <sgtty.h>
outputwait(fd)
int fd;
{
	int outchars;
	while(ioctl(fd, TIOCOUTQ, &outchars) == 0 && outchars > 0)
	{
		sleep(1);
	}
}
Robert Perlberg
Dean Witter Reynolds Inc., New York
phri!{dasys1 | philabs | mancol}!step!perl