summaryrefslogtreecommitdiffstats
path: root/usr.bin/xargs
diff options
context:
space:
mode:
authorallanjude <allanjude@FreeBSD.org>2015-08-04 14:27:25 +0000
committerallanjude <allanjude@FreeBSD.org>2015-08-04 14:27:25 +0000
commit721f0eaa35e61ff5e28f7bebab88017319825ad1 (patch)
treeff79c7901af2efc9cb132bdb45a8cac84cd1da67 /usr.bin/xargs
parentd95709e0297ba6c4d4a4b9081a5afaf6743088d5 (diff)
downloadFreeBSD-src-721f0eaa35e61ff5e28f7bebab88017319825ad1.zip
FreeBSD-src-721f0eaa35e61ff5e28f7bebab88017319825ad1.tar.gz
xargs now takes -P0, creating as many concurrent processes as possible
PR: 199976 Submitted by: Nikolai Lifanov <lifanov@mail.lifanov.com> Reviewed by: mjg, bjk Approved by: bapt (mentor) MFC after: 1 month Relnotes: yes Sponsored by: ScaleEngine Inc. Differential Revision: https://reviews.freebsd.org/D2616
Diffstat (limited to 'usr.bin/xargs')
-rw-r--r--usr.bin/xargs/xargs.17
-rw-r--r--usr.bin/xargs/xargs.c15
2 files changed, 19 insertions, 3 deletions
diff --git a/usr.bin/xargs/xargs.1 b/usr.bin/xargs/xargs.1
index 934d6ed..607b966 100644
--- a/usr.bin/xargs/xargs.1
+++ b/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 August 4, 2015
.Dt XARGS 1
.Os
.Sh NAME
@@ -207,6 +207,11 @@ Parallel mode: run at most
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.
diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c
index b95c7d4..c69a23a 100644
--- a/usr.bin/xargs/xargs.c
+++ b/usr.bin/xargs/xargs.c
@@ -46,9 +46,11 @@ static char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/param.h>
+#include <sys/types.h>
#include <sys/wait.h>
-
+#include <sys/time.h>
+#include <sys/limits.h>
+#include <sys/resource.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
@@ -100,6 +102,7 @@ main(int argc, char *argv[])
long arg_max;
int ch, Jflag, nargs, nflag, nline;
size_t linelen;
+ struct rlimit rl;
char *endptr;
const char *errstr;
@@ -166,6 +169,14 @@ main(int argc, char *argv[])
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;
OpenPOWER on IntegriCloud