About the command line arguments of the main function

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

1 How many array elements can I add to argv[]?

2 What is the maximum size of each char *?

+5
source share
4 answers

You can try:

$ getconf ARG_MAX
2180000

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

ARG_MAX - maximum argument length for exec functions, including environment data.

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

xargs , sysconf(_SC_ARG_MAX);, , getconf ARG_MAX.

Linux . , / . :

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

, ( ).

EDIT: int.

+3

, , . - argv [], . - ,

./javas_program argument1 argument2 argument3

. argc 4, argv[0] ./javas_program, argv[1] argument1, argv[2] argument2 ..

, argv[] . , , .

0

, , . (bash - ), , .

If you run your program through execvor something like that, they should be subject to the same restrictions as any array and string, and as someone said, because argcthere is int, for historical reasons, the limited size intdoes not size_t.

0
source

All Articles