Well, if it all had been in the same program, that would have been easy, you could just store lock requests in an array that you pop them one at a time from, and could display the entries upon request.

However, that is of course not what you would want. Assuming that you only are interested in locks that are made by your own perl programs, you could implement some kind of lock list in a file on disk.

I would probably go about making a lock() module that all your programs use with functions to lock and unlock.

The lock/unlock functions would take, as usual, a filename of the file to lock and unlock. When invoked, lock first would write some identifier (perhaps the name of the invoking script and a timestamp?) to a textfile, probably named by the filename + some extension. Be careful to ensure this file will not exist. Then the file would be locked as usual. When unlocking, the same thing happens, the entry is removed from the textfile and the lock is released. At all times, you could have some function read the entries from this file.

There is one more thing. You should lock and unlock this textfile as well, before reading and updating it, otherwise there will be disaster. :) But because this will be a really fast operation, this should not cause a problem.

The rest you should be able to read up on with: perldoc -f flock and perldoc perlfaq5.

This is not necessarily a very elegant solution, but if you expect to be waiting for locks a lot, you are interested in monitoring this, and you do have control over all the (perl) programs that will do the locking, this should probably work. I think. Someone bash me over the head with my faulty reasoning otherwise...

Sorry I am not providing any example code, you can choose to look at that as an exercise, or take it for what it is - I am tired and a bit lazy. :)


In reply to A double locking scheme perhaps? by Dog and Pony
in thread perl flock queue dumping? by Malus

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.