X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:reply-to:message-id:to:subject :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=LqdVO92J1SqqmFkFNRUOtHRe5KlpZ9JyXzgdIJ5TxtFxdFFv6VCC+ G/UkS5MpCETTlmR+Y1LD4nnAkj7rY6kCiUqCW3Qm2ALb0YhqLHUZtBAH7ILNCozx iJ/QaRPF1Fm0to8/cXI9eTk51i0kdTTiBOxgu6ZM0ssPw6AhybbrfQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:reply-to:message-id:to:subject :mime-version:content-type:content-transfer-encoding; s=default; bh=Q3M56k9qrM2IbURSrCXbFk9KhRo=; b=sNLqAndJL4Cvb+7+PUU7uDEafxds 2fUMH/k40uB7G9TcVufFrJXlRBpat7xyui1JxEtSCujGrdN/dImWtdfo+5xotCnT 8Bjij0aPPLbyf7ug0F44p+bp4azfg5/CHu066ThXe2R3hhhBPvuKamBCL4BhbLQd wfFHQwClmLPThfE= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=4.0 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,KAM_THEBAT,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=H*UA:Bat!, H*x:Bat!, H*r:sk:postmas, H*r:4.80.1 X-HELO: smtp.ht-systems.ru Date: Sun, 3 Apr 2016 00:22:57 +0300 From: Andrey Repin Reply-To: cygwin AT cygwin DOT com Message-ID: <175808986.20160403002257@yandex.ru> To: All Subject: Unreliable flock MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Greetings, All! The script (let's call it test.sh): #!/bin/dash -x _lock="./console-session.lock" { flock -n 9 || { echo "The $(cat "$_lock") command is running already." exit 3 } >&2 printf "$1" >&9 trap 'rm "$_lock";' EXIT HUP INT ABRT TERM sleep 20 } 9>> "$_lock" Very simple in essence. The one-liner: { flock -n 9 && sleep 10 || echo Fail;} 9>> ./console-session.lock Also extremely simple. Open two terminals. mintty or native, bash or dash, doesn't matter. chdir to the directory with the script. Start script in one terminal. ./test.sh Start oneliner in another terminal. Fail. How predictable! Wait till both expire. Now start oneliner first. Then script. Both succeed. Not 100% but highly, highly probable. Sometimes it even work both ways. At the same time, I can't reproduce it on Linux at all. But I do can reproduce it on Cygwin. Both 32 and 64 bit. With both dash and bash. With both local and remote FS. CYGWIN_NT-5.1 foserver 2.4.1(0.293/5/3) 2016-01-24 11:24 i686 Cygwin CYGWIN_NT-6.1 daemon2 2.4.1(0.293/5/3) 2016-01-24 11:26 x86_64 Cygwin CYGWIN_NT-6.1 buildbotw7 2.4.1(0.293/5/3) 2016-01-24 11:26 x86_64 Cygwin -- With best regards, Andrey Repin Saturday, April 2, 2016 23:22:25 Sorry for my terrible english... -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple