9

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?

7

Yes, it's the length in bytes, including the environment.

Very roughly:

$ { seq 1 314290; env; } | wc -c
2091391

linux sysconf

The maximum length of the arguments to the exec(3) family of functions. Must not be less than _POSIX_ARG_MAX (4096).

POSIX 2004 limits.h

Maximum length of argument to the exec functions including environment data. Minimum Acceptable Value: {_POSIX_ARG_MAX}

| improve this answer | |
3

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.