I. Overview
Linux provides a variety of features to achieve file locking. The easiest way to do this is to create a lock file in an atomic way. The so-called "atomic operation" is that when the lock file is created, the system will not allow anything else to happen. This gives the program a way to ensure that the file it creates is unique, and that the file cannot be created by other programs at the same time.
Second, Method
The lock file is just a role that acts as an indicator, and programs need to work together to use them. The lock file is only a suggestive lock, and the opposite is a mandatory lock.
To create a file for use as an indicator, we use the open system call with the O_CREATE and O_EXCL flags. This will allow us to do two things simultaneously with one atomic operation: make sure the file doesn't exist and then create it.
Three, implementation
//file: lock.c#i nclude <unistd.h>#i nclude <stdlib.h>#i nclude < ;stdio.h>#i nclude <fcntl.h>#i nclude <errno.h>int main(){int file_desc;int save_errno;file_desc = open("/tmp/LockFile.test", O_RDWR
I. Manually compile and install 1, download the installation package, wget https://ohse.de/uwe/rele
Problem Description Solution Reasons for analysis, maybe because my platform migr
In Windows, Sogou Pinyin input method has a large number of users because of its large vocabulary an
Linux is a derivative of Unix operating system , Linux has built-in tools to view the current proce
How to modify the Linux computer name
Linux system network card binding implementation tutorial
Optimizing Linux System Hard Disks to Solve Disk Fragmentation
Linux enthusiasts: share my vision of the Linux community
Orphan Process Group and Terminal Session Overview
Xwindow language selection under the Linux operating system
Threaded process classic linux article
How to use rz and sz to transfer files in SecureCRT
How beginners learn Linux system command operations
Linux programming common problems Daquan
Solve Linux system driver synchronization and mutual exclusion
Win7 boot desktop bottom right corner jump out of the USB root hub how to do?
Youku IDO how to stitch video Youku IDO stitching video method
Windows XP clicks on the right amount of memory
Win10 Anniversary Update Cumulative Update KB3201845 Patch Update Content Daquan
Win10 official home version users may be forced to download and install system updates
Win7 notification area icon, computer bottom right corner icon display and hide how to set?