I am writing an a general c program which accepts command line arguments and my doubt is no of command line arguments we can pass and why, on what factor does it depends.
Asked
Active
Viewed 106 times
1
-
1The number of command line arguments is usually limited by the shell. But if you are hitting this limit, you have different problems. Maybe you should rethink your program interface (why does it need so many arguments?) – knittl Jul 30 '14 at 10:59
-
1see following: http://stackoverflow.com/questions/3724369/limit-on-the-number-of-arguments-to-main-in-c – macfij Jul 30 '14 at 11:00
-
1Well, `argc` is an `int`, so if your program is prepared to take `INT_MAX` arguments, you're on the safe side. ;-) Anyhow, the number of command line arguments your program is *willing* to accept is up to you. – DevSolar Jul 30 '14 at 11:08
-
I can't post my answer now as the question's closed (the duplicate doesn't cover Linux, though), so just some hints: `sysconf(_SC_ARG_MAX)`, `execve` man page, section “limits on size of arguments and environment”, and `ARG_MAX` from `
` (` – mafso Jul 30 '14 at 11:31` on my system, not sure about this).
1 Answers
4
The standard doesn't say nothing about the limit of arguments, so INT_MAX
(typically 2^31 - 1
) is assumed.
On Linux, you get the maximum character length of arguments in a shell by running:
getconf ARG_MAX

David Ranieri
- 39,972
- 7
- 52
- 94
-
Note `ARG_MAX` is a number of total bytes, not a count of arguments. – aschepler Jul 30 '14 at 11:13
-
-