Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum length of **argv parameters

Tags:

c

posix

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.

like image 522
Natan Yellin Avatar asked Aug 17 '11 10:08

Natan Yellin


People also ask

Is there a limit on command line 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.

How do I find the length of argv string?

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.

What is the maximum no of arguments that can be given in a command line in C?

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).

What is the maximum number of lines allowed in a shell script?

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 .


1 Answers

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

like image 93
Natan Yellin Avatar answered Sep 22 '22 14:09

Natan Yellin