changed pid file handle creation order, otherwise it runs into a NPE