Correctly close PID file