0

I looked briefly at the source code of xargs in findutils 4.6.0 and saw that 'n' defines: args_per_exec But there seems to be no default value for args_per_exec in find utils

So where is the 'system-defined limit' defined?

It's no duplicate since the question is meant as explanation for the manpage entry, not the generic question for an arbitrary command length

  • Are you saying with your last edit that you are looking for a man-page explanation of args_per_exec? The 'looked briefly at the source code" is misleading in that regard, as then I'd expect references to the source code (as in the linked duplicate) to suffice. – Jeff Schaller Nov 12 '18 at 1:21
  • 1
    The "duplicate" is about the max string length of a single argument from argv supported by the OS, not about how xargs determine how many arguments it could fit in a single command. – mosvy Nov 12 '18 at 8:45
2

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.

| improve this answer | |
  • Well, thanks, wasn't aware of that parameter. That also means that by default the system defined limit is more a character length than an argument count limit, right? – gawain Sep 30 '18 at 9:22
  • exactly, I've updated the answer. – mosvy Sep 30 '18 at 9:24
  • Note that the size of the current environment (all environment variables' names and values, possibly also including terminating nul-characters) also plays into this. See e.g. pubs.opengroup.org/onlinepubs/9699919799/functions/execve.html – Kusalananda Sep 30 '18 at 9:55
  • That's already mentioned that in the first line of my answer. – mosvy Sep 30 '18 at 11:08

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