From: Joey Hess Date: Fri, 10 Jul 2009 14:51:46 +0000 (-0400) Subject: use sysconf to determine number of processors X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5c8031c8f202c8140ee69c901c0e719a244aa77;p=moreutils use sysconf to determine number of processors --- diff --git a/parallel.c b/parallel.c index 0895c13..8045e22 100644 --- a/parallel.c +++ b/parallel.c @@ -30,6 +30,7 @@ #include #include #include +#include void usage() { printf("parallel [OPTIONS] command -- arguments: for each argument, " @@ -121,9 +122,13 @@ int main(int argc, char **argv) { } } - if (maxjobs < 0 && maxload < 0) { - maxjobs = 1; /* XXX: Maybe we should try to autodetect - number of CPUs? */ + if (maxjobs < 0) { +#ifdef _SC_NPROCESSORS_ONLN + maxjobs = sysconf(_SC_NPROCESSORS_ONLN); +#else +#warning Cannot autodetect number of CPUS on this system: _SC_NPROCESSORS_ONLN not defined. + maxjobs = 1; +#endif } while (optind < argc) {