Linux limits two shell scripts to execute simultaneously

Source: Internet
Author: User
Tags flock

The problem arises because the current release is used by executing scripts, all of which are mvn packaged, while execution causes problems.

The solution checks, locks 、、、 before the script executes

#!/bin/bash{flock -n 3 if [ $? -eq 1 ]then    echo   "Other sh running"     while [ 1 ]    do         flock -n 3          [ $? -ne 1 ]&&break;         sleep 1            done     3<>/tmp/.lockfi    echo  "Lock and wait"      Sleep 10} 3<>/tmp/.lock non-blocking mode, no lock, lock continues to execute down, there is a lock loop check, until there is no lock to continue execution. Options and Parameters:-S,--shared: Gets a shared lock that, during the time a shared lock is set on an FD directed to a file without releasing the lock, another process attempts to set an exclusive lock on the FD that is directed to this file to fail, while the other process attempts to set a shared lock on the FD that is directed to this file succeeds. -x,-e,--exclusive: Gets an exclusive lock, or write lock, for the default entry-u,--unlock: Manually release the lock, the general situation does not have to be, when FD shuts down, the system automatically unlocks, this parameter is used in the script command part of the asynchronous execution, part of the situation can be synchronously executed. -n,--nb, --nonblock: Non-blocking mode, when acquiring a lock fails, returns 1 instead of waiting for-W,  --wait, --timeout seconds: Sets the blocking timeout, exits blocking mode when it exceeds the set number of seconds, returns 1, and resumes execution of the following statement-o, -- Close: An FD that closes the set lock before the command is executed so that the command's child process does not remain locked. -c, --command command: Execution of subsequent statements in the shell


This article is from the "Share,open source" blog, so be sure to keep this source http://liqilong2010.blog.51cto.com/3029053/1895513

Linux limits two shell scripts to execute simultaneously

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.