1

What is the maximum number of arguments to an executable on Linux x64 ?

I have reviewed:

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:

  1. Segfualt
  2. 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.

  1. Why do I get the segfaults?
  2. Why am I sometimes able to run the program with a number of arguments and not others?
  3. Why do I get the killed result occationally?
  4. Why can't I grow the stack past ~8MB if the stack has no hard limit?

EDIT: Grammar EDIT2: Completely Rephrased

Apeiron
  • 11
  • 2
  • 1
    possible duplicate of [To check the E2BIG error condition in exec](http://stackoverflow.com/questions/18559403/to-check-the-e2big-error-condition-in-exec) – Jonathan Leffler Apr 07 '14 at 03:07
  • 1
    @JonathanLeffler That Question deals with how to correctly check the E2BIG error when it occurs. My question isn't on how to check the error but when I will get the error. – Apeiron Apr 07 '14 at 03:14
  • If you have to ask, you're almost certainly doing things the wrong way :-) – paxdiablo Apr 07 '14 at 03:19
  • 1
    @paxdiablo I am not doing this to achieve any end other than learning about argument handling and linux. – Apeiron Apr 07 '14 at 03:22
  • There's a program there which attempts to evaluate how big the argument list can be. I find about 1 MiB for the sum of environment plus arguments on Ubuntu 13.10 64-bit with `ulimit -s` reporting `8192` (8 MiB). There's probably still room for improvement in the program, but it will give you some idea, empirically. I can't answer for the theory; I don't know where anyone got the 'one quarter of stack size' information from. – Jonathan Leffler Apr 07 '14 at 04:56
  • You might recompile your recent 3.x kernel by increasing its `#define ARG_MAX` in file `include/uapi/linux/limits.h` – Basile Starynkevitch Apr 07 '14 at 04:58
  • 1
    @JonathanLeffler See fs/exec.c line 210-216 for details! That program calculates the maximum amount of space available that one time. I have done that and saw it varies. I am interested in why it varies and why I can't get anywhere near max. – Apeiron Apr 07 '14 at 05:47
  • 1
    @BasileStarynkevitch As I understand it that limit is not in effect. getconf ARG_MAX gives a much higher number of arguments allowed. I am also able to more than quadruple that number of args in my testing. – Apeiron Apr 07 '14 at 05:56
  • Can someone remove the 'may be answered link'? Does anyone know a what mailing list this question would be proper to ask on? – Apeiron Apr 13 '14 at 23:41
  • It might help if you showed how you (try to) run the program. Also it is not clear (to me) which process segfaults: the called, or the calling one. – Armali Feb 11 '15 at 15:16

0 Answers0