I was reading about flock. The example has this line:
flock($fh, LOCK_EX) or die "Cannot lock mailbox - $!\n";
This call is a blocking call right? So if the lock is already taken the call blocks.
I assume that if the call returns the lock is granted. So when would the die
would occur?
Asked
Active
Viewed 1,289 times
3

Cratylus
- 52,998
- 69
- 209
- 339
1 Answers
9
flock
is a wrapper for the system call of the same name. $!
is set by the system. So consult the system's documentation for your answer.
On my system, as per man 2 flock
,
EBADF
:fd
is not an open file descriptor.EINTR
: While waiting to acquire a lock, the call was interrupted by delivery of a signal caught by a handler; see signal(7).EINVAL
:operation
is invalid.ENOLCK
: The kernel ran out of memory for allocating lock records.EWOULDBLOCK
: The file is locked and theLOCK_NB
flag was selected.

ikegami
- 367,544
- 15
- 269
- 518