我使用下面的代码来检查 replace.exe 的单个实例是否正在运行。当我创建 replace.exe 并在 Windows 上运行时,又创建了一个名为 replace(没有任何扩展名)的 0 kb 大小的文件。
我不希望创建该文件,否则我想在 replace.exe 执行结束后自动删除该文件。
请帮助我。谢谢
use Fcntl qw(:flock);
# Check if any instance of this script is already running
my $lock = "replace";
sub LockOut ( ) {
&print_log ("A instance of this script is running. Therefore exiting. Please try after some time.");
print "A instance of this script is running. Therefore exiting. Please try after some time.";
exit 1;
}
open ( my $pid, '>', $lock );
flock ( $pid, LOCK_EX | LOCK_NB ) or LockOut( );