Fixed warnings about fdopen(). Added wait at the end of main process to reap zombies.