Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 不同数量的最大参数和不同的失败结果_C_Linux_64 Bit - Fatal编程技术网

C 不同数量的最大参数和不同的失败结果

C 不同数量的最大参数和不同的失败结果,c,linux,64-bit,C,Linux,64 Bit,Linux x64上可执行文件的最大参数数是多少 我回顾了: 编辑: 根据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 h

Linux x64上可执行文件的最大参数数是多少

我回顾了:

编辑: 根据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.
 */
根据ulimit和getrlimit(),堆栈有8MB的软限制,没有硬限制

对于常量环境变量和同构参数(均为“1\0”),我可以使用的参数数量会有所不同。当程序无法运行时,我会得到两种不同的行为:

  • 塞福阿尔特
  • 字符串“Killed”打印到控制台
  • 我可以运行程序的最大参数数在前一次运行后增加,接近最大值。连续多次运行该程序,如果我没有超过最大值,最终将导致成功

    在一个使用838325个参数的案例中,前两次运行导致SEGFAULTS,第三次运行成功,ARGV+ENV占用8384282个字节,包括数据和指向数据的指针。5MB短的完整堆栈,不包括堆栈帧,我不知道如何计算这里。使用更多参数(例如1000000)运行编程会导致“Killed”。偶尔,在参数数量较少的情况下,我会收到“Killed”结果

  • 为什么我会得到这些错误
  • 为什么我有时能用一些参数而不是其他参数运行程序
  • 为什么我偶尔会得到杀戮的结果
  • 如果堆栈没有硬限制,为什么不能将堆栈扩展到~8MB以上
  • 编辑:语法
    编辑2:完全重新表述了@JonathanLeffler的可能重复,该问题涉及如何在发生错误时正确检查E2BIG错误。我的问题不是如何检查错误,而是什么时候会出现错误。@paxdiablo我这样做不是为了达到学习参数处理和linux以外的任何目的。@JonathanLeffler有关详细信息,请参阅fs/exec.c第210-216行!该程序计算一次可用的最大空间量。我已经做到了,并且看到了它的变化。我感兴趣的是为什么它会变化,为什么我不能接近max.@BasileStarynkevitch,因为据我所知,这个限制并不有效。getconf ARG_MAX提供了更多允许的参数。在我的测试中,我也能够将args的数量增加到原来的四倍多。