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