#Open a file open(SINGLECHECK,">.server1.pid") or $file->log("$0:Cannot open the lock file $!\n"); #Lock the file in exclusive mode and non-blocking mode so that no two same demon will run. flock(SINGLECHECK, LOCK_EX|LOCK_NB) or ($file->log("$0:server is Already running\n") and exit(1));