Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Locking/unlocking program execution using a queue

by RazorbladeBidet (Friar)
on Mar 30, 2005 at 15:31 UTC ( [id://443506]=note: print w/replies, xml ) Need Help??


in reply to Re: Locking/unlocking program execution using a queue
in thread Locking/unlocking program execution using a queue

Interesting idea. However, I don't have much control over the system and the reader script could be killed accidentally (or intentionally), so that's a little concerning.

What I was hoping for was some sort of IPC... the same script adding to the FIFO and being awoken.

The only problem with the sleep above is that the processes could get out of order... I'd rather keep it all in the same script if possible.
--------------
"But what of all those sweet words you spoke in private?"
"Oh that's just what we call pillow talk, baby, that's all."
  • Comment on Re^2: Locking/unlocking program execution using a queue

Replies are listed 'Best First'.
Re^3: Locking/unlocking program execution using a queue
by polettix (Vicar) on Mar 30, 2005 at 15:47 UTC
    You can take into account the accidental kill by putting some monitor script in the crontab itself - but you would have an explosion of scripts :)

    My previous solution was clean in the sense that it voids active waits. If you don't bother having slightly active waits, you could keep a queue file in each directory, with write access protected via a lock, in which you append your 'name' (e.g. pid number), then keep controlling until it's your turn. When you're done, you simply remove yourself from the top of the file (using the same locking to prevent multiple writings). In this way, the access to the queue file should be rather quick, then a check every second should suffice without slowing your machine to a crawl.

    Note that if you use PIDs, you can also check if the current first-in-the-list is alive, just to prevent infinite locking by a badly dead script.

    Flavio

    Don't fool yourself.
      There is also a problem if the reading script stalls and requests continue to be written, overflowing the FIFO's buffer. Nonetheless it would normally work and if the commands are short a lot of them would fit into 4kB or whatever size the FIFO buffer is.
        No, thats not a problem because every program trying to overflow the FIFO will stall itself and give enough CPU to the stalled script to empty the buffer. The kernel sees to that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://443506]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-19 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found