delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2012/05/31/20:55:47

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,KHOP_RCVD_UNTRUST,KHOP_THREADED,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL
X-Spam-Check-By: sourceware.org
Message-ID: <20120601095531.2520@binki>
Date: Fri, 01 Jun 2012 09:55:31 +1000
From: wynfield AT gmail DOT com
To: <cygwin AT cygwin DOT com>
Subject: Re: Shell script loop runs out of memory
In-reply-to: Your message of Thu, 31 May 2012 17:42:30 +0000 (UTC) <loom.20120531T193933-322@post.gmane.org>
References: <loom DOT 20120531T193933-322 AT post DOT gmane DOT org>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com


I will not address the memory management problem, if there is one here.
I am addressing your method of determing a difference.

No offense, but it seems extremely inefficient, and the larger the file you are computnig the md5sum on the more inefficient.

Why not use the file system's "modified" flag, or even, depending on the types of changes you are expecting you could just check for a file-size change.  Using either of these means that you wouldn't even have to open the file, let alone, slog through x 
bytes to compute an md5hash value.  In terms of both computer resource usage and speed this would be a far better method in my opinion to the method you currently use.

Regards



Jordan <uptownb0y AT yahoo DOT com> wrote:

> Hi folks,
> 
> I've written a shell script running under CygWin, the purpose of which is to 
> monitor a file for changes. If the MD5 hash fails to match the previous hash, it 
> will execute a command to process the file. I used a 1-second delay between 
> checks of the hash. This works great for several hours, but then gives an "out 
> of memory" error and actually brings Windows 7 to its knees.
> 
> The script uses a loop within a loop; the outer loop is infinite by design, and 
> the inner loop ends when it finds a non-matching hash and processes the file. It 
> broke while running the inner loop, without the file having been modified at 
> that point in time. The file was modified numerous times previously, triggering 
> the code below the inner loop, but not around the time when the memory error 
> occurred.
> 
> I am just wondering why the loops here are consuming increasing amounts of 
> memory over time?  I'm assigning new MD5 values into existing variables over and 
> over, not allocating new variables for each MD5 assignment. (Right??) Is 1 
> second perhaps too short a delay... does the system need time to deallocate 
> something between each iteration of the inner loop?
> 

--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019