In Linux, the command for setting locks in shell scripts-general Linux technology-Linux programming and kernel information. The following is a detailed description. The two formats are:
-S is a shared lock. During the time when a shared lock is set for the FD of a file but no lock is released, other processes attempt to set an exclusive lock on the FD of this file, other processes attempt to set a shared lock on the FD of this file.
-E is an exclusive or exclusive lock. Within the time when the exclusive lock is set for the FD of a file but the lock is not released, other processes attempt to set a shared or exclusive lock on the FD of this file. If the-s parameter is not set, this parameter is set by default.
-U is manually unlocked. Generally, this parameter is not required. When FD is disabled, the system automatically unlocks it. this parameter is used when some script commands need to be executed asynchronously and some can be executed synchronously.
-N is in non-blocking mode. If a lock fails to be set, 1 is returned in non-blocking mode and the following statement is executed.
-W sets the blocking timeout. When the set number of seconds is exceeded, the blocking occurs. 1 is returned and the following statement is executed.
-O is available only when the first format is used. This indicates that the FD set to lock is disabled before the command is executed, so that the sub-process of the command does not keep the lock.
The function of this example is that when one script instance is being executed, the other process attempting to execute the script will fail to exit. Sleep can be replaced with the statement segment you want to execute.
Note that I use <> to open mylockfile because the targeted file descriptor is executed before the command. Therefore, if you need to read and write the mylockfile file in the statement segment to be executed, for example, you want to obtain the pid of the previous script instance and write the pid of this script instance to mylockfile. In this case, directly use> on behalf of mylockfile to clear the last stored content, and use
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