SUMMARY: How to: File locking with perl

From: Brian Sherwood <sherwood_at_esu.edu>
Date: Wed, 5 Feb 1997 09:56:38 -0500 (EST)

Thanks to all that replied.
I ended up using peices of a script from Eric Z. Ayers to create the
following small test program.

I was using "sslli" for my flags to pack. Eric's "ssiii" worked much
better.

Something strange though, I could not get the "open" to open a file
read/write without first truncating it. I had to use "sysopen".


#!/usr/local/bin/perl

use Fcntl;
use POSIX;

$INFILE="qwqwqwqw";

$flags="ssiii";
$s_flock = pack ($flags,F_WRLCK,SEEK_CUR,1,0,0);
_at_ary=unpack $flags,$s_flock;
print "_at_ary\n";


sysopen (INFILE,$INFILE,O_RDWR|O_EXCL) or die "sysopen infile";
fcntl (INFILE,F_SETLKW,$s_flock) or die "fcntl:$!:";
print "After fcntl\n";
$ttt=<STDIN>;
seek (INFILE,0,SEEK_END);
print INFILE $ttt;
close (INFILE);


-------------------------------------------------------
Brian Sherwood E-mail: sherwood_at_esu.edu
Network Administrator Phone: 717-422-3299
East Stroudsburg University
East Stroudsburg PA 18301
Received on Wed Feb 05 1997 - 16:22:03 NZDT

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:47 NZDT