add read error handler; add waitpid