Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

flock -- and indefinite wait

by Xxaxx (Monk)
on Jul 23, 2003 at 06:23 UTC ( [id://277049]=perlquestion: print w/replies, xml ) Need Help??

Xxaxx has asked for the wisdom of the Perl Monks concerning the following question:

Don't know how I went so long without getting this right, be that as it may, I need to straighten my flock out.

In case you haven't already guessed I've run into the "it waits indefinitely until the lock is granted" (Perl 5.6.0 Documentation) problem.

Fumbling around with this has raised several questions.

1) Under what condition does the sleep then try lock again mechanism so popular in file locking subroutines make any sense -- if it waits forever to lock the file maybe once is enough?

2) Is there a way to make an attempt to lock a file that will time out or give up after a certain amount of time?

3) In testing to find out what was happening I've created several dozen flocking-lost scripts that seem to just hang around forever. What is there to do about this?

It's easy enough to telnet into the server and kill the pid for each (abandoned? zombie? runaway?) script. I suppose if I knew the proper terminalogy for these I could better find where this is talked about.

I suppose if I solve the problem of indefinite wait for flock the runaway scripts problem will go away. However, I'd still be interested in links to a proper discussion of that issue.

I fully expect these subjects have been well-discussed else where. But in reading the various threads I'm not seeing any discussion of what to do to prevent the script just hanging around forever.

Thanks in advance.
Claude Needham

Replies are listed 'Best First'.
Re: flock -- and indefinite wait
by Xxaxx (Monk) on Jul 23, 2003 at 07:50 UTC
    Well... <embarassed grin> after reading past paragraph two in the flock perldoc (5.6.0) I found the answer to much of the above.

    Then I stumbled across tilly's node about "flock feedback". That answered much of the rest of the above questions.

    I'm still puzzled by the proliferation of loop code sans the "| LOCK_NB".

    And, I'm still killing run-a-muck perl scripts by hand.

    So if you can overlook my previous inability to get past paragraph two in the perldoc, maybe someone will have a clue about how to do the clean-up of scripts left dangling by an escaping browser.

    Thanks Claude

      "...maybe someone will have a clue about how to do the clean-up of scripts left dangling by an escaping browser."

      Well, do you know what causes them to "dangle"? Are they all waiting on a lock? If so, tilly's node should provide a good solution to your problem; i.e., using LOCK_NB and retrying.
      Alternatively, you can use alarm(). Signal handling is pretty reliable if you're careful; i.e., instead of dumping loads of potentially non-reentrant code into the handler itself, just set a flag and handle the condition in your main program.

      --perlplexer
Re: flock -- and indefinite wait
by Mr_Person (Hermit) on Jul 23, 2003 at 19:02 UTC
    I would recommend reading through Dominus's excellent presentation, File Locking Tricks and Traps. In particular, Slide 8 talks about different methods of handling waiting for a lock if it cannot be obtained immediately.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 10:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found