in reply to Re: pesky lockfile stays locked
in thread pesky lockfile stays locked

I also thought that program termination released locks, that's what puzzles me most.
My apologies, but the lock in my code is actually LOCK_EX (I copied the code directly from the book instead of from my program).
Unfortunately I've never witnessed the last run of the program before it stops, so I've no idea how it dies. I'm just assuming that it's the lockfile because as soon as I delete it all other programs run freely again. On average it occurs once every 2 days.
I'm going to try coding in an END block and see if that alleviates the problem...... time will tell.

Thanks everyone for your replies.

Replies are listed 'Best First'.
Re: Re: Re: pesky lockfile stays locked
by dave_the_m (Monsignor) on May 17, 2004 at 15:10 UTC
    A better thing to do would be, the next time it hangs, to do lsof lockfile (if you're on an OS that supports this), to see what process(es) still have the lock file open. Unless you have a very screwed-up OS, a process must habe an open file descriptor on a file to hold a lock.
Re: pesky lockfile stays locked
by Abigail-II (Bishop) on May 17, 2004 at 15:06 UTC
    Are you sure the program terminates? If a program hangs for some reason, no other program can continue, but removing the lockfile will "solve" the problem (well, not the problem - just the symptom, and it might cause data corruption - you are using locking for a reason).

    If all the programs that hold the lock terminate, and the file is still locked, the fault lies in your kernel, not in perl. It should be impossible for a file to be locked, without a locking process.

    Abigail

Re: Re: Re: pesky lockfile stays locked
by Thelonius (Priest) on May 17, 2004 at 15:24 UTC
    My apologies, but the lock in my code is actually LOCK_EX (I copied the code directly from the book instead of from my program).
    Don't do that. Copy and paste your actual code. Your problem may be some really subtle thing in your code, not the book.

    Unfortunately I've never witnessed the last run of the program before it stops, so I've no idea how it dies. I'm just assuming that it's the lockfile because as soon as I delete it all other programs run freely again.
    Huh? What do you mean "the last run of the program before it stops"? If it doesn't stop, why do you think it closes the file? Or do you mean that there are several processes all running the same code? When you say "all other programs", do you mean all other processes running the same code, or processes running different code? If it is different code, you need to post that, too.