What is the maximum number of arguments to an executable on Linux x64 ?
I have reviewed:
- http://www.in-ulm.de/~mascheck/various/argmax/
- https://psomas.wordpress.com/2011/07/15/arg_max-and-the-linux-kernel/
EDIT: According to fs/exec.c 210-216:
/*
* Limit to 1/4-th the stack size for the argv+env strings.
* This ensures that:
* - the remaining binfmt code will not run out of stack space,
* - the program will have a reasonable amount of stack left
* to work from.
*/
The stack has a soft limit of 8MB, and and no hard limit according to ulimit, and getrlimit().
With constant environment variables, and homogeneous arguments (all "1\0"), the number of arguments I can run the program with varies. I get two diffrent behaviors when the program fails to run:
- Segfualt
- The string "Killed" printed to the console
The maximum number of arguments I can run the program with goes up after previous runs, towards a maximum. Running the program multiple times in a row, if I haven't exceeded that maximum will eventaully result in a sucess.
In one case with 838325 Arguments, the first two runs resulted in SEGFAULTS, and the third was sucessful with ARGV + ENV taking 8384282 Bytes Including data, and pointers to data. 5MB short of the full stack, not including stack frames, which I do not no how to calculate here. Running the programming with many more arguments, ex 1000000, results in "Killed". Occationally, with a smaller number of arguments I recieve the "Killed" result.
- Why do I get the segfaults?
- Why am I sometimes able to run the program with a number of arguments and not others?
- Why do I get the killed result occationally?
- Why can't I grow the stack past ~8MB if the stack has no hard limit?
EDIT: Grammar EDIT2: Completely Rephrased