flock FILEHANDLE, OPERATION |
支持文件鎖定在指定的文件句柄,使用係統的flock(),fcntl()文件鎖定,或使用lockf()。確切的實現是依賴於你的係統支持。操作是此處定義的靜態值之一...
Operation Result LOCK_SH Set shared lock. LOCK_EX Set exclusive lock. LOCK_UN Unlock specified file. LONG_NB Set lock without blocking.
0 設置/取消鎖定失敗時
1 設置/取消鎖定成功時
以下是用法...
這裡有一個郵箱附加器 BSD係統:
use Fcntl ':flock'; # import LOCK_* constants
sub lock {
flock(MBOX,LOCK_EX);
# and, in case someone appended
# while we were waiting...
seek(MBOX, 0, 2);
}
sub unlock {
flock(MBOX,LOCK_UN);
}
open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
or die "Can't open mailbox: $!";
lock();
# by www.gitbook.net
print MBOX $msg,"\n\n";
unlock();