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 July 29, 2015 .Dt XARGS 1 .Os .Sh NAME @@ -207,6 +207,11 @@ invocations of .Ar utility at once. +If +.Ar maxprocs +is set to 0, +.Nm +will run as many processes as possible. .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 @@ -46,9 +46,10 @@ #include __FBSDID("$FreeBSD$"); -#include +#include #include - +#include +#include #include #include #include @@ -100,6 +101,7 @@ long arg_max; int ch, Jflag, nargs, nflag, nline; size_t linelen; + struct rlimit rl; char *endptr; const char *errstr; @@ -166,6 +168,14 @@ maxprocs = strtonum(optarg, 1, INT_MAX, &errstr); if (errstr) errx(1, "-P %s: %s", optarg, errstr); + if (getrlimit(RLIMIT_NPROC, &rl) != 0) + errx(1, "getrlimit failed"); + if (*endptr != '\0') + errx(1, "invalid number for -P option"); + if (maxprocs < 0) + errx(1, "value for -P option should be >= 0"); + if (maxprocs == 0 || maxprocs > rl.rlim_cur) + maxprocs = rl.rlim_cur; break; case 'p': pflag = 1;