perl,php程序只运行一个

perl
my $lock_file = getcwd()."/test_speed.lck";
open LCK,">$lock_file" or die "failed to open test_speed lock";
flock(LCK, LOCK_EX | LOCK_NB) or die "failed to aquire test_speed lock";
print LCK $$;
chmod 0700,$lock_file;
 

php

if(PHP_OS=="Linux")
{
	$fpid=$basdir."get_all_url.pid";
	if(is_file($fpid))
	{
		$oldpid=file_get_contents($fpid);
		$oldpid = preg_replace("/\s|\r|\n/","",$oldpid);
		$cmd=" ps axu|awk '{print \$2}'|grep -e \"^".$oldpid."\$\"|wc -l";
		$ret=`$cmd`;
		if($ret>0) die("find old running!");
	}
	$pid=posix_getpid();
	file_put_contents($fpid,$pid); 
}


你可能感兴趣的:(linux,PHP,File,cmd,OS,perl)