About command line arguments of main function

后端 未结 4 1352
暗喜
暗喜 2020-12-19 07:44

It will look like int main(int argc, char *argv[]);. My questions are:

1 How many array items can I add in argv[]?

2 What is MAX si

4条回答
  •  时光取名叫无心
    2020-12-19 08:24

    You can try:

    $ getconf ARG_MAX
    2180000
    

    http://pubs.opengroup.org/onlinepubs/007904975/basedefs/limits.h.html

    ARG_MAX is maximum length of argument to the exec functions including environment data.

    That is, there is no individual limit on the number of arguments or argument's length. Only the limit on total size required to store all the arguments and environment variables.

    xargs figures out maximum command line length using sysconf(_SC_ARG_MAX); which yields the same value as reported by getconf ARG_MAX.

    On Linux command line arguments and environment variables are put into new process' stack. So, the process/thread maximum stack size is the ultimate upper bound. Linux-specific limits are hardcoded in the kernel:

    #define MAX_ARG_STRLEN (PAGE_SIZE * 32)
    #define MAX_ARG_STRINGS 0x7FFFFFFF
    

提交回复
热议问题