|
Home > Archive > Unix Shell > March 2004 > Limit to the length of argument list
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Limit to the length of argument list
|
|
|
| Hi,
I wondered what is the exact meaning of the
system variable ARG_MAX. I got "1048320" by
running "getconf ARG_MAX" in my system. But
it reports "Arg list too long" when I ran a
command whose length is about 1044043.
So ... I want to know, what is the exact length limitation of the Unix
command? Is
it ARG_MAX plus something? If so, what is
this "something"?
thanks
| |
| Alexis Huxley 2004-03-29, 2:39 am |
| > I wondered what is the exact meaning of the
> system variable ARG_MAX. I got "1048320" by
> running "getconf ARG_MAX" in my system. But
> it reports "Arg list too long" when I ran a
> command whose length is about 1044043.
>
> So ... I want to know, what is the exact length limitation of the Unix
> command? Is
> it ARG_MAX plus something? If so, what is
> this "something"?
Take a look at the limits.h file somewhere under /usr/include
(exactly where depends on your OS). There are probably some
comments in it that explain these things. E.g. on Linux:
dione$ less /usr/include/linux/limits.h
...
#define ARG_MAX 131072 /* # bytes of args + environ for exec() */
...
So you were on the right lines, but you needed to leave room for
the environment variables. Try subtracting the result of
'env | wc -c' from the above number to see the maximum argument
size. (It should be right, env vars are separated with 0-value
bytes in memory, but with newlines in 'env' output so they should
add up to the same thing.)
*But* you're probably going to hit a limit imposed by the shell
if you try this from the command line (e.g. maximum line length or
maximum number of arguments). If you want to try to hit the
ARG_MAX limit then you'll probably have to write a little C
program that just calls exec().
Alexis
| |
|
| "Alexis Huxley" <ahuxley@gmx.net> wrote in message
news:slrnc6fjfh.2j1.ahuxley@dione.no-ip.org...
>
> Take a look at the limits.h file somewhere under /usr/include
> (exactly where depends on your OS). There are probably some
> comments in it that explain these things. E.g. on Linux:
>
> dione$ less /usr/include/linux/limits.h
> ...
> #define ARG_MAX 131072 /* # bytes of args + environ for exec() */
> ...
>
> So you were on the right lines, but you needed to leave room for
> the environment variables. Try subtracting the result of
> 'env | wc -c' from the above number to see the maximum argument
> size. (It should be right, env vars are separated with 0-value
> bytes in memory, but with newlines in 'env' output so they should
> add up to the same thing.)
>
Thanks for your explanation. I think I have got your meaning. But the
result of 'env | wc -c' on my machine is only 864, which is far smaller
than the difference of 1044043 ( which I got the 'arg list too long'
error) and 1048320 (which is the value of my ARG_MAX)
> *But* you're probably going to hit a limit imposed by the shell
> if you try this from the command line (e.g. maximum line length or
> maximum number of arguments). If you want to try to hit the
> ARG_MAX limit then you'll probably have to write a little C
> program that just calls exec().
The command I run is "ls $CMD" where $CMD consists of about
1044 strings separated by spaces, each string is about 1000 bytes.
I have done other tests to ensure that neither '1000' hit the maximum
line length limit nor '1044' hit the maximum number of argument limit.
And per the error message, "arg list too long", the limit I hit here is
really "ARG_MAX". But what's the explanation for the difference?
>
> Alexis
| |
| Dan Mercer 2004-03-29, 12:38 pm |
|
"mrby" <bianying@msn.com> wrote in message news:c4924c$27cm$1@mail.cn99.com...
: "Alexis Huxley" <ahuxley@gmx.net> wrote in message
: news:slrnc6fjfh.2j1.ahuxley@dione.no-ip.org...
: > > I wondered what is the exact meaning of the
: > > system variable ARG_MAX. I got "1048320" by
: > > running "getconf ARG_MAX" in my system. But
: > > it reports "Arg list too long" when I ran a
: > > command whose length is about 1044043.
: > >
: > > So ... I want to know, what is the exact length limitation of the Unix
: > > command? Is
: > > it ARG_MAX plus something? If so, what is
: > > this "something"?
: >
: > Take a look at the limits.h file somewhere under /usr/include
: > (exactly where depends on your OS). There are probably some
: > comments in it that explain these things. E.g. on Linux:
: >
: > dione$ less /usr/include/linux/limits.h
: > ...
: > #define ARG_MAX 131072 /* # bytes of args + environ for exec() */
: > ...
: >
: > So you were on the right lines, but you needed to leave room for
: > the environment variables. Try subtracting the result of
: > 'env | wc -c' from the above number to see the maximum argument
: > size. (It should be right, env vars are separated with 0-value
: > bytes in memory, but with newlines in 'env' output so they should
: > add up to the same thing.)
: >
: Thanks for your explanation. I think I have got your meaning. But the
: result of 'env | wc -c' on my machine is only 864, which is far smaller
: than the difference of 1044043 ( which I got the 'arg list too long'
: error) and 1048320 (which is the value of my ARG_MAX)
:
: > *But* you're probably going to hit a limit imposed by the shell
: > if you try this from the command line (e.g. maximum line length or
: > maximum number of arguments). If you want to try to hit the
: > ARG_MAX limit then you'll probably have to write a little C
: > program that just calls exec().
:
: The command I run is "ls $CMD" where $CMD consists of about
: 1044 strings separated by spaces, each string is about 1000 bytes.
: I have done other tests to ensure that neither '1000' hit the maximum
: line length limit nor '1044' hit the maximum number of argument limit.
: And per the error message, "arg list too long", the limit I hit here is
: really "ARG_MAX". But what's the explanation for the difference?
:
: >
: > Alexis
:
:
env|wc -c will not count the true length of your env vars - you will be missing
the NUL byte that is part of each string. Similarly, I will bet your
arithmetic was off by one byte per string for your arglist.
Dan Mercer
| |
| Barry Margolin 2004-03-29, 1:39 pm |
| In article <gUY9c.43275$4B1.999@twister.rdc-kc.rr.com>,
"Dan Mercer" <dmercer@mn.rr.com> wrote:
> env|wc -c will not count the true length of your env vars - you will be
> missing
> the NUL byte that is part of each string.
But "env|wc -c" will count the newline that's printed between each
string, which is the same length as the null byte that it's not
counting, so the total should be correct.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
| |
| Sven Mascheck 2004-03-29, 2:36 pm |
| Barry Margolin wrote:
> "Dan Mercer" wrote:
>
> But "env|wc -c" will count the newline that's printed between each
> [...]
Still missing are the sizeof(char *) for each pointer in
argv[] and envp[], though (e.g. "expr `env|wc -l` \* 4").
--
<URL:http://www.in-ulm.de/~mascheck/various/argmax/>
|
|
|
|
|