Skip to content

Instantly share code, notes, and snippets.

@olegwtf
Last active November 11, 2016 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olegwtf/68e859016c2602ac4342b4c8e2a93b25 to your computer and use it in GitHub Desktop.
Save olegwtf/68e859016c2602ac4342b4c8e2a93b25 to your computer and use it in GitHub Desktop.
package ScriptLock;
use strict;
use FindBin;
use Fcntl ':flock';
my $fh;
sub import {
return if $fh;
open $fh, '<', "$FindBin::Bin/$FindBin::Script"
or die "open: $!";
flock $fh, LOCK_EX|LOCK_NB
or die "flock: $!";
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment