Exit forked process properly, record exit code in history