Re: grep bug

From: Robin Schoonover <end_at_endif.cjb.net>
Date: Fri, 13 Feb 2004 20:45:21 -0700
On Fri, 13 Feb 2004 19:51:23 -0700, Steve Young wrote:
>
> Arguably grep shouldn't eat up all your 
> memory when this happens but that's more of a GNU issue than a FreeBSD 
> issue, and really it would be kind of hard to handle 
> gracefully/portably.  Have you reported this to the gnu bugs mailing 
> address? It may conceivably use 100% CPU but it shouldn't try and grab 
> 100% memory too.
> 

grep has to pull in the entire line, and /dev/zero is a line with no
end, so it tries pulling it all into memory until there is no more memory
for a line to go into.  (This part has been mentioned on this list before.)

The reason is simple: regular expressions.  You may have a regex that
matches from beginning to end (^ to $), which means we need the entire line
before we can determine if there is a match or not.  plain grep (as far as
I know) shouldn't require an entire line to operate on, just the length of
the search.  (There may be other reasons too)

However, you rarely have lines long enough to make enough of a difference
to cause problems.  (1000 char lines? 1000000 char lines?)  IMHO, it
wouldn't be worth making the grep code more complex to handle such rare
cases.  

-- 
Robin Schoonover (aka End)
# "The POP3 server service depends on the SMTP server service, which
# failed to start because of the following error:
# The operation completed successfully."    -- Windows NT Server v3.51
Received on Fri Feb 13 2004 - 18:45:24 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:43 UTC