How do I lock a file in Perl?

前端 未结 14 604
礼貌的吻别
礼貌的吻别 2020-12-01 05:45

What is the best way to create a lock on a file in Perl?

Is it best to flock on the file or to create a lock file to place a lock on and check for a lock on the lock

14条回答
  •  鱼传尺愫
    2020-12-01 06:06

    Flock is probably the best but requires you to write all the supporting code around it - timeouts, stale locks, non-existant files etc. I trued LockFile::Simple but found it started setting the default umask to readonly and not cleaning this up. Resulting in random permissions problems on a multi process/multi-threaded application on modperl I've settled on wrapping up NFSLock with some empty file handling.

提交回复
热议问题