8
7
6
5
4
3
2
1
####
1
2
3
4
5
####
#! /usr/local/bin/perl
chomp($pid = $$);
$LOCK_EXCLUSIVE = 2;
$UNLOCK = 8;
$fifo = "ENV{HOME}/a_file";
popup($fifo);
sub popup
{
my($fifo) = @_;
while (! -e "$fifo.lock")
{
open (LOCK, "> $fifo.lock") || die "problem opening $fifo\n";
flock LOCK , $LOCK_EXCLUSIVE;
print LOCK $pid;
open (FILE, "< $fifo") || die "problem opening $fifo\n";
@lines = ;
close(FILE) || warn "update queue file exited $?\n";;
open (FILE, "> $fifo") || die "problem opening $fifo\n";
@sorted = sort @lines;
$pop = shift @sorted;
print "$hostname is poping $pop\n";
print FILE "@sorted\n";
close(FILE) || warn "update queue file exited $?\n";;
close(LOCK) || warn "lock file exited $?\n";;
$str=`cat $fifo.lock`;
flock LOCK, $UNLOCK;
}
if ($pid eq $str)
{
print "PID lock file is going to be removed\n" ;
system("rm $fifo.lock");
}
}
####
linux24 is poping
PID lock file is going to be removed
linux28 is poping
PID lock file is going to be removed
####
chdir; # go home
$FIFO = '.signature';
$ENV{PATH} .= ":/etc:/usr/games";
while (1) {
unless (-p $FIFO) {
unlink $FIFO;
system('mknod', $FIFO, 'p')
&& die "can't mknod $FIFO: $!";
}
# next line blocks until there's a reader
open (FIFO, "> $FIFO") || die "can't write $FIFO: $!";
print FIFO "John Smith (smith\@host.org\n";
close FIFO;
sleep 2; # to avoid dup signals
}