On POSIX-like systems, is there a maximum length for command line arguments?
To clarify, I'm looking for the maximum length of each command line argument, not the maximum number of arguments.
The maximum length of the string that you can use at the command prompt is 8191 characters. This limitation applies to: the command line. individual environment variables that are inherited by other processes, such as the PATH variable.
argv is an array of pointers to char (i.e. array of strings). The length of this array is stored in argc argument. strlen is meant to be used to retrieve the length of the single string that must be null-terminated else the behavior is undefined.
No, there is no limit imposed by the ISO C99 standard. If you're using the "blessed" main form (of which there are two): int main (int argc, char *argv[]); then you will be limited to the maximum size of a signed integer (implementation-dependent but guaranteed to be at least 215-1 or 32,767).
The shell/OS imposed limit is usually one or two hundred thousand characters. getconf ARG_MAX will give you the maximum input limit for a command. On the Debian system I currently have a terminal open on this returns 131072 which is 128*1024 .
POSIX doesn't define a maximum length for each argument.
MAX_ARG_STRLEN
is a Linux-specific constant which was introduced in the 2.6.25 kernel.
As of the 2.6.25 kernel, MAX_ARG_STRLEN
is defined as 131072 bytes
=32 pages of memory
.
(I'm assuming a pagesize of 4k, which is the case unless CONFIG_HUGETLB_PAGE
is enabled. I'm not sure how CONFIG_HUGETLB_PAGE
affects MAX_ARG_STRLEN
.)
See also: http://manpages.ubuntu.com/manpages/lucid/man2/execve.2.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With