Set an exclusive lock on the pid file, refactoring