Linux recommended lock and Force lock

Source: Internet
Author: User

Llinxu Mandatory lock default is not open, want to let Linux support mandatory lock, not only when the mount is required to add-o mand, and

The files you want to lock are also required to set permissions.

1. The proposed lock industry is called a cooperative lock, for this type of lock, the kernel knowledge provides the addition of lock and detect whether lock operation, but does not provide lock control and

Work together, that is, if an application operates on a file, there is no detection of locks or

Ignoring the lock and writing data directly to the file, the kernel will not block control. Therefore, the recommended lock does not prevent the process from manipulating the file,

And can only rely on the people consciously to detect whether to lock and then restrain their behavior;

2. Force Lock: Is the file lock of the OS kernel. Each time you operate on a file, such as when you perform an operation such as Open, read|, write, the OS detects whether the file is forced to lock

, if the lock causes these file operations to fail, that is, the kernel forces the application to comply with the rules of the game;

3. Child processes generated by fork do not inherit the locks set by the parent process. means that if a process gets a lock and then calls Fork, the child process is considered another process for the parent process to acquire the lock, and for the any descriptor inherited from the parent process, the child process needs to call Fcntl to get its own lock.

This is discriminated against the lock as another process, and for the any descriptor inherited from the parent process, the child process needs to call Fcntl to get

It's own lock. This is consistent with the function of the lock, which is to prevent multiple processes from manipulating the same file at the same time, if the child process

Inherits the lock of the parent process, the parent-child process operates on the same file, which is incompatible with the original intent of the lock;

4. After exec executes, the new program can inherit the lock of the original execution program, but note that if a file descriptor is set to close

-on-exec flag, when the file descriptor is closed as part of exec, all locks on the corresponding file are freed.

Linux recommended lock and Force lock

Related Article

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.