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
This commit is contained in:
Allan Jude 2015-08-04 14:27:25 +00:00
parent 3208d3ff46
commit e896b4a4f0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=286289
2 changed files with 19 additions and 3 deletions

View File

@ -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.

View File

@ -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;