Visit Our UNIX and Linux User Community


maximum number of arguments


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers maximum number of arguments
# 8  
Old 10-18-2007
In general, the number of arguments which can be passed depends on ARG_MAX and LINE_MAX (See limits.h).
# 9  
Old 10-18-2007
POSIX_LINE_MAX or LINE_MAX talks about the max length of records that can be read in by utilities like awk.

According to POSIX:
Quote:
{ARG_MAX}
Maximum length of argument to the exec functions including environment data.
Minimum Acceptable Value: {_POSIX_ARG_MAX}
which is what Porter was talking about earlier.

Short answer: For POSIX, it is not the number of arguments, but the total size of data (arguments and env) that invokes a limit. This is why you see results that vary.

Plus you shoud try:
Code:
total=$(( `set | wc -c`  + ` set | wc -l `))

and substract that value from ARG_MAX in limits.h to see how much space your arguments have left to occupy. Each argument and each environment variable has overhead, possibly alignment overhead, and definitely trailing nuls for strings.

Environment variables are stored like this in memory
Code:
ENV_variable_name=some value\000

# 10  
Old 10-15-2008
Quote:
Originally Posted by matrixmadhan
What is the maximum number of arguments that could be passed to zsh ?
To find out that I tried a simple script.
And the maximum number of arguments that could be passed turned out to be 23394

Code:
 ...
subIndex=23000
while [ $i -le $subIndex ]
do
  arg=$arg" "$i
  i=$(($i + 1))
done ...

Am not sure whether this approach is current or not.
(Earlier postings here suggested, that you missed to count your environment. But that is not a plausible explanation for the huge difference .)

Your approach has this flaw: It hits the maximum length of args, not the maximum number, because in average your arguments are too long!

The maximum length on Linux-pre-2.6.23 is 131072.
Your environment is about 2k. Now estimate the length of all your args:
About 9 single digit args (1..9) (each with a trailing ASCII-NUL, add one for the length),
about 90 double digit args (10..99), round numbers are easier,
and so on:

Code:
$ bc
9*2 + 90*3 + 900*4 + 9000*5 + 13394*6    + 2000
131252

This is almost identical to the expected limit.

You will only hit the maximum number of arguments (on Linux-pre-2.6.23) if the average length is at most 4.

Last edited by s.mascheck; 10-16-2008 at 05:59 PM.. Reason: wrong code tags around calculation fixed
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #975
Difficulty: Easy
In July 2009, Alan Cox quit his Linux kernel development role as the TTY layer maintainer after disagreement with Linus Torvalds about who should pay for beers during a trip to Amsterdam.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Maximum number of sed squeezing

Hi all, What is the maximum number of sed squeezing in one shell?? I've surprised with this message when I squeezed 50 sed in the same shell: 253: Identifier too long - maximum length is 18.This is what I've did in my sed query | sed -e "s/ 0 /Default /" | sed -e "s/ 1 ... (2 Replies)
Discussion started by: leo_ultra_leo
2 Replies

2. Shell Programming and Scripting

Maximum number from input by user

I am trying to calculate the maximum number from four numbers input by the user. I have the following code, but it does not work. It says there's an error with the last line "done". Any help would be appreciated. max=0 echo "Please enter four numbers: " for i in 1 2 3 4 do read number... (17 Replies)
Discussion started by: itech4814
17 Replies

3. Shell Programming and Scripting

Maximum command line arguments

Hi, Can anyone please help me to know what is the maximum number of command line arguments that we can pass in unix shell script? Thanks in advance, Punitha.S (2 Replies)
Discussion started by: puni
2 Replies

4. Shell Programming and Scripting

Maximum number of characters in a line.

Hi, Could any one please let me know what is the maximum number of characters that will fit into a single line of a flat file on a unix. Thanks. (1 Reply)
Discussion started by: Shivdatta
1 Replies

5. UNIX for Dummies Questions & Answers

ls - maximum number of files

what is the maximum number ls can list down (6 Replies)
Discussion started by: karnan
6 Replies

6. Solaris

Maximum Number of threads suuported????

Hi, Anybody knows the maximum number of threads suuported by a process in solaris os. Please reply Thanks in advance :( (1 Reply)
Discussion started by: Agnello
1 Replies

7. Programming

maximum number of dots in a domain name

maximum number of dots in a domain name - not a sub-domain name. for example: mydomain.com ------ one dot mydomain.com.au ------ two dots do you know maximum number of dots in a domain name and could you provide a sample? thx. (1 Reply)
Discussion started by: hello20009876
1 Replies

8. UNIX for Dummies Questions & Answers

Maximum number of users allowed

How do i determen (what command) the max. number of users allowed Thanks in advance (10 Replies)
Discussion started by: siza
10 Replies

9. UNIX for Advanced & Expert Users

Maximum number of threads per user

Anybody knows how to setup Maximum number of threads per user or some other value on Sun Solaris 8. (1 Reply)
Discussion started by: s_aamir
1 Replies

Featured Tech Videos