Implement safe-pidfile and safe-pidfile2