Siebel eScript Language Reference > Siebel eScript Commands > File I/O Methods in eScript >

Clib.flock() Method

This method locks or unlocks a file for simultaneous use by multiple processes.


Clib.flock(filePointer, mode)



A file pointer as returned by Clib.fopen() or Clib.tmpfile()


One of the following:

  • LOCK_EX (lock for exclusive use)
    LOCK_SH (lock for shared use)
    LOCK_UN (unlock)
    LOCK_NB (nonblocking)

0 if successful; otherwise, a nonzero integer.


The flock() function applies or removes an advisory lock on the file identified by filePointer. Advisory locks allow cooperating processes to perform consistent operations on files. However, other processes may still access the files, which can cause inconsistencies.

The locking mechanism allows two types of locks: shared and exclusive. Multiple processes can have shared locks on a file at the same time; however, there cannot be multiple exclusive locks, or shared locks and an exclusive lock, on one file at the same time.

Read permission is required on a file to obtain a shared lock, and write permission is required to obtain an exclusive lock. Locking a segment that is already locked by the calling process causes the old lock type to be removed and the new lock type to take effect.

If a process requests a lock on an object that is already locked, the request is locked until the file is freed, unless LOCK_NB is used. If LOCK_NB is used, the call fails and the error EWOULDBLOCK is returned.

NOTE:  Clib.flock() is not supported in Unicode builds. It always returns 0.

Siebel eScript Language Reference