Key Points of Linux File lock

Source: Internet
Author: User
Linux File Lock key points-general Linux technology-Linux programming and kernel information, the following is a detailed description. Du XiaoGang

File lock is one of the most common inter-process synchronization mechanisms in Linux. Compared with sysv semaphores, file locks are easier to use (the trouble of sysv semaphores lies in its key Acquisition Mechanism ).

APUE provides a detailed description of the file lock. Note the following points. For the original article, see section 14.3 of APUE2:

1. The file lock (file_lock) is bound to the file (specifically the file inode) and process. The file_lock structure of the file in the Linux implementation is mounted to the inode structure corresponding to the file, the file_lock structure contains the pid of the process to which the lock belongs. This implementation method has two consequences:

A. When a process exits, all file locks belonging to the process are released.

B. When any fd or file to which the lock process belongs is disabled, the lock is released. This is because the file_lock structure is mounted on inode rather than fd or file (the next stop of fd in the kernel structure), so it is impossible to distinguish the fd or file corresponding to the file lock. Note that two examples are listed on APUE. The first one is fd disabled, and the second one is file disabled. Both cases will cause lock release:
QUOTE:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.