You should use the warnings and strict pragmas so the second and third lines of your program should be:
use warnings; use strict;
chomp($pid = $$);
$$ does not contain a newline so there is no point in using chomp().
$LOCK_EXCLUSIVE = 2; $UNLOCK = 8;
You should use the constants from the Fcntl module:
use Fcntl ':flock';
$fifo = "ENV{HOME}/a_file";
You probably meant to use the %ENV hash there:
$fifo = "$ENV{HOME}/a_file";
close(FILE) || warn "update queue file exited $?\n";
The $? variable will only contain useful information if you are running an external program. which you are not. However, you should include the $! variable in any system error messages.
close(LOCK) || warn "lock file exited $?\n";; $str=`cat $fifo.lock`; flock LOCK, $UNLOCK;
close(LOCK) will also unlock the file so the subsequent attempt to unlock it is superfluous.
system("rm $fifo.lock");
Is there a reason that you couldn't use the built-in unlink function?

Have you read the entries in perlfaq5 on file locking?

You are locking the PID file but not the data file. This may work better:

#!/usr/local/bin/perl use warnings; use strict; use Fcntl ':flock'; use Tie::File; my $fifo = "$ENV{HOME}/a_file"; my $lock = "$fifo.lock"; tie( my @pid, 'Tie::File', $lock )->flock( LOCK_EX ) or die "Cannot open '$lock' $!"; @pid = $$; tie( my @lines, 'Tie::File', $fifo )->flock( LOCK_EX ) or die "Cannot open '$fifo' $!"; ( my $pop, @lines ) = sort @lines; print "$hostname is poping $pop\n"; untie @lines; print "PID lock file is going to be removed\n"; untie @pid; unlink $lock or die "Cannot unlink '$lock' $!"; __END__

In reply to Re: mkfifo/mknode by jwkrahn
in thread mkfifo/mknode by azaria

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.