Cleanup code that does waiting for process exit and elapsed time computation