Understanding Lock Types

There are two basic forms of file locking. They are

  • Lock files

  • Locked regions

The first form requires that a process create and open a lock file before it writes to the protected data file. If a process fails to create the lock file, then it sleeps for a while and tries again.

For example, if the data file database.dat is the data file, then the lock file might be named database.lck. The contents of the lock file are not important to the procedure, and it may even be empty. When the updating process has finished with its update of database.dat, then the lock file database.lck is released. This method works only when all processes cooperate and obey this procedure.

The UNIX kernel also will permit a process to lock regions ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.