[perl][重複][チェック]

こんなんで

perl hoge.pl

hoge.pl

  1 use strict;
  2 use warnings;
  3
  4 my $file_name = '/var/tmp/hoge.pl';
  5 my $LOCK_FILE;
  6
  7 open( $LOCK_FILE , '>' , $file_name );
  8
  9 flock $LOCK_FILE , 6 ;
 10
 11 system('./hoge2.pl');
 12
 13 close( $LOCK_FILE );

hoge2.pl

  1 #!/usr/bin/perl
  2 use strict;
  3 use warnings;
  4
  5 my $file_name = '/var/tmp/hoge.pl';
  6 my $LOCK_FILE;
  7
  8 open( $LOCK_FILE , '>' , $file_name );
  9
 10 my $status = flock( $LOCK_FILE , 6 );
 11
 14 if( not  $status ) {
 15     warn 'This file is locked by other process.';
 16 }
 19
 20 close( $LOCK_FILE );