Re: programming help
#! /bin/perl
# -*- Mode: Perl -*-
# lock-news.pl ---
# Author : Manoj Srivasta ( srivasta@pilgrim.umass.edu )
# Created On : Tue Apr 30 01:10:07 1996
# Created On Node : melkor.pilgrim.umass.edu
# Last Modified By : root
# Last Modified On : Tue Apr 30 01:36:52 1996
# Last Machine Used: melkor.pilgrim.umass.edu
# Update Count : 18
# Status : Unknown, Use with caution!
# HISTORY :
# Description :
#
#
package main;
use strict;
#These variables we know about:
my($FILE, $another_program, $LOCK_SH, $LOCK_EX, $LOCK_NB, $LOCK_UN);
$FILE='/tmp/junk';
$another_program='/bin/echo';
$LOCK_SH = 1;
$LOCK_EX = 2;
$LOCK_NB = 4;
$LOCK_UN = 8;
# if file does not exist or was modified more than 7 says ago,
if (! -e "$FILE" || -M _ > 7) {
my $now_string = localtime;
my $exitval;
open (LOCK, ">>$FILE") or die "Could not open $FILE:$!";
lock(); #lock the file and do stuff.
print LOCK "$now_string\n\n";
$exitval = system $another_program,
"The file should be locked at this time\n";
print STDERR "The system call returned status ", $exitval/256, "\n";
unlock();
}
# Do the rest
&execute_program(@ARGV);
# Fill in the blanks here ...
sub execute_program {
my @local_args = @_;
}
# BTW, this is in the manpages for perl ...
sub lock {
flock(LOCK,$LOCK_EX);
# and, in case someone appended
# while we were waiting...
seek(LOCK, 0, 2);
}
sub unlock {
flock(LOCK,$LOCK_UN);
}
__END__
hope this helps.
manoj
--
The society which scorns excellence in plumbing because plumbing is a
humble activity and tolerates shoddiness in philosophy because
philosophy is an exalted activity will have neither good plumbing nor
good philosophy. Neither its pipes nor its theories will hold water.
-- John W. Gardner %%
Manoj Srivastava Systems Research Programmer, Project Pilgrim,
Phone: (413) 545-3918 A143B Lederle Graduate Research Center,
Fax: (413) 545-1249 University of Massachusetts, Amherst, MA 01003
<srivasta@pilgrim.umass.edu> <URL:http://www.pilgrim.umass.edu/%7Esrivasta/>
Reply to: