39

What is the maximum length of command line arguments in gnome-terminal?

... and is there a system environment variable which reports this value?

1

3 Answers 3

34

xargs knows. On my system,

$ xargs --show-limits
Your environment variables take up 2572 bytes
POSIX upper limit on argument length (this system): 2092532
POSIX smallest allowable upper limit on argument length (all systems): 4096
Maximum length of command we could actually use: 2089960
Size of command buffer we are actually using: 131072
3
  • 5
    To expand on this, the limit is not in the terminal, it's in the kernel (and in the shell, as well, but I think the default shell (bash)'s limit is as high as the kernel limit). Also, xargs isn't just for reporting the limit, it's also (primarily) for working around it — see the man page or other documentation. Nov 19, 2010 at 22:57
  • 1
    I like this answer, particularly because of the "could actually use" output... I've twiddled with it a bit and came up with this command variant to isolate the "actually" value... (maybe there's a simpler way, but hey, it works and is suitable for a script: xargs --show-limits --no-run-if-empty < /dev/null 2>&1 |sed -n "/could actually use/s/.*: \\([0-9]\+\\)/\1/p"
    – Peter.O
    Nov 20, 2010 at 4:57
  • 1
    Strangely, xargs seems to double-count the environment limit in the POSIX limit (POSIX limit = ARG_MAX - 2048 (headroom) - envvars).
    – Tobu
    Nov 17, 2012 at 14:00
18

The answer comes from the sysconf value ARG_MAX. To examine it on your system:

getconf ARG_MAX

For me, this reports 2097152. For more details check the manpage:

man sysconf

To get this inside a program, for example:

#include <unistd.h>
...
printf("%ld\n", sysconf(_SC_ARG_MAX));
1
  • 1
    Thanks KC.. +1; a neat way to get the absolute MAX, but I've preferred the xargs method because of its "actually available" factor... as I was actually after a run-time value (but I didn't mention that :(
    – Peter.O
    Nov 20, 2010 at 5:09
0

I don't really know about gnome-terminal, but the shell has not a 'fixed' limit, but the limit of the stack.

However there is an hardcode limit per-argument that is 128KB, that should not be a problem if you don't use 'very very very long arguments....'.

You can read more about this here:

http://www.mail-archive.com/[email protected]/msg05522.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .