On Sat, Nov 08, 2003 at 11:34:10PM +0800, Rafael 'Dido' Sevilla wrote:
> On Sat, Nov 08, 2003 at 06:54:58AM -0000, Marc Henry Galang wrote:
> > hmm... you're having that kind of error too? Whats your condition when
> > that message was outputed? im having that one too, its really annoying,
> > even when you remove some of the files to be greped it still outputs that
> > message.
> > 
> 
> This is a limitation of the shell, a limitation that seems to have
> existed in the earliest days of Unix that the authors of the Bourne
> Again Shell have not seen fit to fix (seems strange because a lot of the
> internal limitations of many of the original POSIX commands have
> disappeared in the GNU versions of the same).  There's an absolute limit
> of 5000 or so characters in the length of any command line, which is why
> you get the 'argument list too long' error message, which is not
> generated by grep but by the shell. 

Well, 5000 characters is a big step up from when I first used Unix about
15 years ago.  I think the limit on Ultrix was ~800 characters.  A not
too large directory caused problems.

I'm thinking that the limitation under Linux may be a limitation in
exec.  Check out "man 2 execve", and search for "E2BIG".  There is a
limitation to argument list size in the kernel, that may ultimately be
the real limitation.

Okay, realizing that I have the source, I checked it out.  This is the
case.  Look in fs/exec.c (in the Linux source) and you can see around
line 900 where it does an actual check based on a certain amount of
memory that it's willing to allocate for the argument list and
environment list.  The "count" function is defined earlier, you can find
it by searching for E2BIG.

In include/linux/binfmts.h:
* MAX_ARG_PAGES defines the number of pages allocated for arguments
#define MAX_ARG_PAGES 32

It's 32 pages (at 4096 bytes per page, I think) divided by 4, the
pointer size.  So it's 32K for the list.

So I'm looking in bash2 on FreeBSD here.  I have a directory with 1965
files, and "ls *" works fine.  As does "echo *", of course.  I have
another directory with 7959 files, and I get "Argument list too long."
for it.

velma# ls 1* 2* 3* 4* 5* 6* 7* 8*| wc -l
    7130
velma# ls 1* 2* 3* 4* 5* 6* 7* 8* 9*| wc -l
/bin/ls: Argument list too long.

velma# ls 1* 2* 3* 4* 5* 6* 7* 8* | wc -c
   64374

So the limit is 64K.  "echo *" works, which strengthens my belief that
the limitation is due to exec.  Not sure where I'm off by 2.

Let's look and see where that's coming from.  Well, "man errno" seems to
help:

    7 E2BIG Argument list too long.  The number of bytes used for the argu-
            ment and environment list of the new process exceeded the current
            limit of 65536 bytes (NCARGS in <sys/param.h>).

usr/include/sys/param.h:
#define        NCARGS          ARG_MAX /* max bytes for an exec function */

/usr/include/sys/syslimits.h:
#define    ARG_MAX                 65536 /* max bytes for an exec function */

I believe that the exec simply fails and sets errno to E2BIG, and
strerror prints this out.  Still not sure why my math is off, but it's
late.

Michael
-- 
Michael Darrin Chaney
[EMAIL PROTECTED]
http://www.michaelchaney.com/
--
Philippine Linux Users' Group (PLUG) Mailing List
[EMAIL PROTECTED] (#PLUG @ irc.free.net.ph)
Official Website: http://plug.linux.org.ph
Searchable Archives: http://marc.free.net.ph
.
To leave, go to http://lists.q-linux.com/mailman/listinfo/plug
.
Are you a Linux newbie? To join the newbie list, go to
http://lists.q-linux.com/mailman/listinfo/ph-linux-newbie

Reply via email to