Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

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

share|improve this question
add comment

3 Answers

up vote 14 down vote accepted

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
share|improve this answer
3  
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. –  Gilles Nov 19 '10 at 22:57
    
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 '10 at 4:57
    
Strangely, xargs seems to double-count the environment limit in the POSIX limit (POSIX limit = ARG_MAX - 2048 (headroom) - envvars). –  Tobu Nov 17 '12 at 14:00
add comment

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));
share|improve this answer
    
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 '10 at 5:09
add comment

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/bug-make@gnu.org/msg05522.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.