X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_50,GENERIC_IXHASH,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Content-Class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Subject: RE: Shell script loop runs out of memory Date: Thu, 31 May 2012 13:43:47 -0500 Message-ID: <786EBDA1AC46254B813E200779E7AD36023A42C2@srv1163ex1.flightsafety.com> In-Reply-To: References: From: "Thrall, Bryan" To: CC: "Thrall, Bryan" X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: 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 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by delorie.com id q4VIi6Xd024159 AZ 9901 wrote on 2012-05-31: > 2012/5/31 Jordan : > Then, when (bash) scripting under Cygwin, you must take care to avoid > forking as much as possible. > > You could try to improve the "sleep 1" loop with the following one : > > while md5sum $FILE_TO_CHECK | cut -d " " -f1 | grep -q "^$MD5PRINT$" > do > sleep 1 > done > > Note that MD5PRINTNEW is no more useful here. > With this loop we avoid the fork done by > MD5PRINTNEW=`md5sum $FILE_TO_CHECK | cut -d " " -f1` Doesn't that just replace the 2 MD5PRINTNEW forks (md5sum and cut) with 3 (md5sum, cut, and grep)? Seems like the (untested) following would be better (in terms of fewer forks): TMPFILE=$(mktemp) md5sum $FILE_TO_CHECK > "$TMPFILE" ... while md5sum -c "$TMPFILE" do sleep 1 done rm "$TMPFILE" -- Bryan Thrall Principal Software Engineer FlightSafety International bryan DOT thrall AT flightsafety DOT com