Fixed pidfile locking to check for an existing pidfile.