rewrite of locking of pid and client/server detection