tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: Brian Sherwood <sherwood () esu ! edu>
To: tru64-unix-managers
Subject: SUMMARY: How to: File locking with perl
Date: Wed, 05 Feb 1997 14:56:38 +0000	[thread overview]
Message-ID: <96078608810111.tru64-unix-managers.marc@archive.invalid> (raw)



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);
@ary=unpack $flags,$s_flock;
print "@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@esu.edu
Network Administrator                Phone:   717-422-3299
East Stroudsburg University
East Stroudsburg PA 18301

                 reply	other threads:[~1997-02-05 14:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox