Following ARG_MAX, maximum length of arguments for a new process it seems like ARG_MAX is wrongly (or at least ambiguously) defined on my Mac Mini 3,1 running Ubuntu 12.04:
$ getconf ARG_MAX # arguments 2097152 $ locate limits.h | xargs grep -ho 'ARG_MAX[ t]+[0-9]+' | uniq | cut -d ' ' -f 8 131072
The actual limit seems to be somewhere between these:
$ cd "$(mktemp -d)" $ touch $(seq 1 131072) && find . -mindepth 1 -printf x | wc -c && rm * 131072 $ touch $(seq 1 131073) && find . -mindepth 1 -printf x | wc -c && rm * 131073 $ touch $(seq 1 $(getconf ARG_MAX)) && find . -mindepth 1 -printf x | wc -c && rm * bash: /usr/bin/touch: Argument list too long
I did a small search:
cd "$(mktemp -d)"
min=131072
max=2097152
while true
do
search=$((min + (max - min) / 2))
if touch $(seq 1 $search) 2>/dev/null
then
min=$search
else
max=$search
fi
[[ $((max - min)) -le 1 ]] && echo "ARG_MAX = $min" && break
done
Eventually this resulted in ARG_MAX = 314290, which doesn’t seem to have any relation to either of the ARG_MAX values found before. Is this normal? Is there a simpler way to find the actual ARG_MAX?
Did I misunderstand the definition of ARG_MAX? It seems it’s actually the byte (or possibly character) length of the arguments with or without (?) the separating spaces. If it’s really the byte length, are there also other restrictions?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Yes, it’s the length in bytes, including the environment.
Very roughly:
$ { seq 1 314290; env; } | wc -c
2091391
The maximum length of the arguments to the exec(3) family of functions.
Must not be less than _POSIX_ARG_MAX (4096).
Maximum length of argument to the exec functions including environment data.
Minimum Acceptable Value: {_POSIX_ARG_MAX}
Method 2
The page that you linked to about ARG_MAX states that as of kernel version 2.6.23 it is 1/4th the stack size. It even links to the git commit responsible.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0