From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 66609 invoked by alias); 27 Feb 2016 22:28:45 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 66596 invoked by uid 89); 27 Feb 2016 22:28:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=4.9 required=5.0 tests=AWL,BAYES_80,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS,TBC autolearn=no version=3.3.2 spammy=Enterprise, txt, edition, Questions X-HELO: DUB004-OMC1S15.hotmail.com Received: from dub004-omc1s15.hotmail.com (HELO DUB004-OMC1S15.hotmail.com) (157.55.0.214) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA256 encrypted) ESMTPS; Sat, 27 Feb 2016 22:28:43 +0000 Received: from DUB115-W24 ([157.55.0.239]) by DUB004-OMC1S15.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Sat, 27 Feb 2016 14:28:40 -0800 X-TMN: [6e1trjg6EDf264bX9ALATfHpeaUxyWsc] Message-ID: From: Matthijs Nescio To: "cygwin@cygwin.com" Subject: echo -n or sleep 0 needed to unblock Bourne shell script Date: Sat, 27 Feb 2016 22:28:00 -0000 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-IsSubscribed: yes X-SW-Source: 2016-02/txt/msg00419.txt.bz2 Hi, Sorry for replying in a new thread. =A0=A0=A0 =A0=A0=A0 Hi, =A0=A0=A0 =A0=A0=A0 I have the strangest problem. I am running some complic= ated advanced Bourne shell scripting. These scripts work fine under Ubuntu = 14.04 LTS. However, in Cygwin I have to add some strange commands with no o= bvious effect; without these the scripts just hang. I can not disclose the = scripts completely because they are company property. I realise that this d= oes not comply to the rules of smart questions, but if anybody else has thi= s problem the Cygwinners need to know about it. I do not exactly know when = these problems started. I reinstalled Cygwin twice, several weeks ago and y= esterday evening (25-2-2016). =A0=A0=A0 =A0=A0=A0 I have had this problem with several complicated, lengt= hy scripts. Debugging using echo debug statements is hard because the echo = makes the problem go away. When I discovered similar problems in multiple s= cripts, I reinstalled Cygwin, but the problem persists. Also rebooting my W= indows 7 Enterprise edition machine does not solve the problem. I have had = some experienced colleagues to look at this and they were as flabbergasted = as I was. =A0=A0=A0 =A0=A0=A0 Examples: =A0=A0=A0 =A0=A0=A0 =A0=A0 TTP_FILE_DR_KML=3D`echo $TTP_FILE.dr.kml | sed -= s 's#\.txt\.#\.#g'` =A0=A0=A0 =A0=A0=A0 =A0=A0 #echo -n> /dev/null =A0=A0=A0 =A0=A0=A0 =A0=A0 sleep 0 =A0=A0=A0 =A0=A0=A0 =A0=A0 if [ "`convert_needed "$TTP_FILE_DR_KML"`" =3D "= convert" ] =A0=A0=A0 =A0=A0=A0 =A0=A0 then =A0=A0=A0 =A0=A0=A0 In the examples above and below, either the sleep or th= e echo has to be commented in, otherwise the script just hangs. In the exam= ple below the doit function needs the echo or sleep, otherwise it does not = return. =A0=A0=A0 =A0=A0=A0 doit() =A0=A0=A0 =A0=A0=A0 { =A0=A0=A0 =A0=A0=A0 =A0=A0 # 8< code removed =A0=A0=A0 =A0=A0=A0 =A0=A0 #echo -n =A0=A0=A0 =A0=A0=A0 =A0=A0 sleep 0 =A0=A0=A0 =A0=A0=A0 } =A0=A0=A0 =A0=A0=A0 In =A0=A0=A0 =A0=A0=A0 =A0 order to investigate this problem the Cywinners wil= l need more information. Feel free to ask, but it may not be legal for me t= o share. =A0=A0=A0 =A0=A0=A0 Questions: =A0=A0=A0 =A0=A0=A0 * Was a similar issue ever reported? I have looked, but= did not find anything. =A0=A0=A0 =A0=A0=A0 * Is there a solution? =A0=A0=A0 =A0=A0=A0 Thank you, kind regards, Matthijs. Marco Atzeri answered: =A0=A0=A0 I suspect you hit a corner case of resource race. =A0=A0=A0 May be as the time for execution is very short : =A0=A0=A0 $ time echo -n> /dev/null 0 =A0=A0=A0 real=A0=A0=A0 0m0.000s =A0=A0=A0 user=A0=A0=A0 0m0.000s =A0=A0=A0 sys=A0=A0=A0=A0 0m0.000s =A0=A0=A0 $ time sleep 0 =A0=A0=A0 real=A0=A0=A0 0m0.070s =A0=A0=A0 user=A0=A0=A0 0m0.015s =A0=A0=A0 sys=A0=A0=A0=A0 0m0.062s =A0=A0=A0 As both the two commands are just supposed to waste minimal time, =A0=A0=A0 what was the original need of both of them ? The explaination of the issue may not be clear. I have to add the sleep 0 o= r the echo in order to keep my scripts running. Without these the scripts h= ang. Sometimes they can be interrupted by CTRL-C, sometimes they do not res= pond. The doit() function fails to end all together without the sleep. So t= he sleep 0 was not there before, it is needed for the flow of the script al= l of a sudden. Obviously, if adding an echo to a script changes the behaviour, it is kind = of hard to prove that an empty echo has an effect. Again, I showed it to tw= o colleagues who were surprised too. Together there was over 30 years of Bo= urne shell experience looking at the problem. The script containing the doit function is single-threaded, so there is no = race condition in the script. Actually, it should just end itself after the= curly brace. Without either the sleep or the echo it just hangs. Note also= that the reproducibility is 100%, which is not expected from a race condit= ion of marginal time differences. With reproducibility here I mean: adding = the sleep/echo gives the normal flow, removing the sleep/echo gives a hangi= ng script. Questions: * Were there changes in the Bourne shell interpreter in 2015/2016? * Are these interpreters well-tested for regression? * Are similar issues reported? Thank you, kind regards, Matthijs. =20=09=09=20=09=20=20=20=09=09=20=20 -- 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