Index: usr.bin/xargs/xargs.1 =================================================================== --- usr.bin/xargs/xargs.1 +++ usr.bin/xargs/xargs.1 @@ -33,7 +33,7 @@ .\" $FreeBSD$ .\" $xMach: xargs.1,v 1.2 2002/02/23 05:23:37 tim Exp $ .\" -.Dd March 16, 2012 +.Dd May 21, 2015 .Dt XARGS 1 .Os .Sh NAME @@ -207,6 +207,11 @@ invocations of .Ar utility at once. +If +.Ar maxprocs +is negative or 0, +.Nm +will run as many processes as possible at a time. .It Fl p Echo each command to be executed and ask the user whether it should be executed. Index: usr.bin/xargs/xargs.c =================================================================== --- usr.bin/xargs/xargs.c +++ usr.bin/xargs/xargs.c @@ -48,6 +48,8 @@ #include #include +#include +#include #include #include @@ -63,6 +65,8 @@ #include "pathnames.h" +#define BASE_DECIMAL 10 + static void parse_input(int, char *[]); static void prerun(int, char *[]); static int prompt(void); @@ -100,6 +104,7 @@ long arg_max; int ch, Jflag, nargs, nflag, nline; size_t linelen; + size_t proclen; char *endptr; inpline = replstr = NULL; @@ -159,8 +164,14 @@ oflag = 1; break; case 'P': - if ((maxprocs = atoi(optarg)) <= 0) - errx(1, "max. processes must be >0"); + maxprocs = strtol(optarg, &endptr, BASE_DECIMAL); + if (*endptr != '\0') + errx(1, "max processes must be a number"); + if (maxprocs > nargs) + errx(1, "max processes must be %d or less", nargs); + if (maxprocs < 1) + proclen = sizeof(maxprocs); + sysctlbyname("kern.maxproc", &maxprocs, &proclen, NULL, 0); break; case 'p': pflag = 1;