diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-07-03 11:48:06 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-07-03 11:48:06 +0200 |
commit | 99c5a7c96e441f4d336740a2624de072a075c3ae (patch) | |
tree | 5477280e7de827157a2b06b06cbaba1f4502c61b | |
parent | e28e002ebca7b7746cc6a65db84e902634027d40 (diff) | |
download | xe-99c5a7c96e441f4d336740a2624de072a075c3ae.tar.gz xe-99c5a7c96e441f4d336740a2624de072a075c3ae.tar.xz xe-99c5a7c96e441f4d336740a2624de072a075c3ae.zip |
parse_jobs: accept a multiplier on the CPU core number
-rw-r--r-- | xe.1 | 8 | ||||
-rw-r--r-- | xe.c | 27 |
2 files changed, 29 insertions, 6 deletions
diff --git a/xe.1 b/xe.1 index 4dbb15e..162d05c 100644 --- a/xe.1 +++ b/xe.1 @@ -1,4 +1,4 @@ -.Dd November 30, 2016 +.Dd July 3, 2017 .Dt XE 1 .Os .Sh NAME @@ -118,6 +118,12 @@ processes concurrently. Using .Fl j0 will run as many processes as there are CPU cores running. +If +.Ar maxjobs +ends with an +.Sq Ic x , +it is regarded as a multiplier on the number of running CPU cores +(rounded down, but using at least one core). .El .Sh ENVIRONMENT The environment variable diff --git a/xe.c b/xe.c index 2825396..946ec5a 100644 --- a/xe.c +++ b/xe.c @@ -240,11 +240,28 @@ parse_jobs(char *s) char *e; int n; - errno = 0; - n = strtol(s, &e, 10); - if (errno != 0 || *e) { - fprintf(stderr, "xe: can't parse number '%s'.\n", s); - exit(1); +#ifdef _SC_NPROCESSORS_ONLN + if (s[strlen(s) - 1] == 'x') { + n = (int)sysconf(_SC_NPROCESSORS_ONLN); + double d = 0.0; + errno = 0; + d = strtod(s, &e); + if (errno != 0 || *e != 'x' || d <= 0) { + fprintf(stderr, "xe: can't parse multiplier '%s'.\n", s); + exit(1); + } + n = (int)(d * n); + if (n < 1) + n = 1; + } else +#endif + { + errno = 0; + n = strtol(s, &e, 10); + if (errno != 0 || *e) { + fprintf(stderr, "xe: can't parse number '%s'.\n", s); + exit(1); + } } #ifdef _SC_NPROCESSORS_ONLN |