wait until dead before cleaning up the temp dir

closes #5774