grep bug
Robin Schoonover
end at endif.cjb.net
Fri Feb 13 19:45:24 PST 2004
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
More information about the freebsd-current
mailing list