in reply to use die with flock

You should still check your open command for failure. It could fail for a number of reasons that have nothing to do with your flock call. That said, flock isn't going to die if a file is locked, rather it waits forever to get one and it dies if the platform doesn't support it, therefore IMHO checking the return status of flock is really not nessecary at all. Someone please correct me if I'm wrong.

Lobster Aliens Are attacking the world!

Replies are listed 'Best First'.
Re: use die with flock
by Abigail-II (Bishop) on Jul 24, 2003 at 15:17 UTC
    A flock can fail, even if the system supports and if you are not using LOCK_NB. See your systems manual page for lockf, flock and fcntl. (Perl can implement flock in different ways, depending on what the OS supports). One reason of failures is when you've reached the systems limit of locks.

    It's better to always check the return value of system calls. No harm is done if the system call cannot fail, but much harm could be done if you wrongly assumed it cannot fail, and it failed after all.

    The only time you don't need to check the return value of a system call is when you don't care if it fails. But then you should place a comment there, explaining why you aren't checking the return value of the system call.

    Abigail