The limit is sysconf(_SC_ARG_MAX)
, including the environment strings and 2048 bytes of headroom. That's the maximum length of the actual strings + the separating null bytes, not the number of arguments. This is from GNU xargs
' source:
/* IEEE Std 1003.1, 2003 specifies that the combined argument and
* environment list shall not exceed {ARG_MAX}-2048 bytes. It also
* specifies that it shall be at least LINE_MAX.
*/
long val;
#ifdef _SC_ARG_MAX
val = sysconf (_SC_ARG_MAX);
if (val > 0)
{
assert (val > XARGS_POSIX_HEADROOM);
/* Note that val can in fact be greater than ARG_MAX
* and bc_ctl.arg_max can also be greater than ARG_MAX.
*/
bc_ctl.arg_max = smaller_of (bc_ctl.arg_max,
(size_t)val-XARGS_POSIX_HEADROOM);
That is then clamped to 128k in bc_use_sensible_arg_max()
, but which could be increased via the -s
option:
void
bc_use_sensible_arg_max (struct buildcmd_control *ctl)
{
#ifdef DEFAULT_ARG_SIZE
enum { arg_size = DEFAULT_ARG_SIZE };
#else
enum { arg_size = (128u * 1024u) };
#endif
Both the limit calculation and the clamping are the same for find -exec ... {} +
; the code from above is duplicating the logic from bc_get_arg_max()
and bc_init_controlinfo()
, the latter of which is called with a headroom
argument of 2048 from both find/parser.c
and xargs/xargs.c
.
GNU xargs also has a --show-limits
option.