Patch from tilman2: Close PID-file