in reply to flock() ..I really need a hand .. please :)

You'll be glad to know that a file-based semaphore already exists on CPAN as File::CounterFile. Pick it up!
AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
  • Comment on Re: flock() ..I really need a hand .. please :)

Replies are listed 'Best First'.
Re: Re: flock() ..I really need a hand .. please :)
by Anonymous Monk on Mar 20, 2001 at 12:17 UTC
    Hello, Thank you all for your wisdom. I do appreciate the help & tips:

    a, just to clarify, all the files were using the same $SEMAPHORE file, so any instance of $tempfile getting written to, $tempfile was locked. I double checked the locks as well, by placing the sleep method KM had discussed. The lock was working when I had checked. (Using the names "$tempfile" and "$file" were actually just examples, in the code the real file names are placed instead.)

    I dunno, I've gone over this a bizillion times and double checked everywhere, and it only happens once in a while where the file gets wiped. I really like KM's method because it does make sense, and that's probably the first time flock() actually makes sense to me. I would guess it's better than when I first began using just flock(FILE,2);

    I'll keep plunking away at it, and hopefully I'll get something that will work. Also thanks for the tip to debug "rename" I'll add that right away.

    AgentM Thank you for letting me know about the module File::CounterFile I went and took a look, it looks interesting enough, but it says under Bugs that it uses the flock(2); method. This was something I was trying to avoid. What are your feeling on that?

    Well Thanks again, I do appreciate the help :-)

    PS.. Thanks turnstep that search was great!!

      The "bug" reports that flock is not entirely cross-platform (it's emulated decently on most systems which don't natively support flock but do support advisory locking). That simply means the target system needs to support flock (advisory locks). The report suggests a File::Lock module which doesn't exist (perhaps a good idea).
      AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.