#!/usr/bin/perl -w use strict; use Fcntl qw(F_WRLCK SEEK_SET F_SETLKW); open(F,"+< $ARGV[0]") or die "Couldn't lock myself: $!\n"; my $args = pack("sslli",F_WRLCK,SEEK_SET,0,0,$$); fcntl(F,F_SETLKW,$args) or die "Couldn't lock: $!\n"; print "File locked\n"; sleep(1000);