diff options
author | Joey Hess <joey@gnu.kitenet.net> | 2009-07-10 10:51:46 -0400 |
---|---|---|
committer | Joey Hess <joey@gnu.kitenet.net> | 2009-07-10 10:51:46 -0400 |
commit | b5c8031c8f202c8140ee69c901c0e719a244aa77 (patch) | |
tree | b6742cdc57a1a2218b3046cb5b1e7a36676a192d | |
parent | ab46fb8018f45a5584485edfd3c0caa82f3fd9b4 (diff) | |
download | moreutils-b5c8031c8f202c8140ee69c901c0e719a244aa77.tar.gz |
use sysconf to determine number of processors
-rw-r--r-- | parallel.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -30,6 +30,7 @@ #include <sys/select.h> #include <sys/types.h> #include <sys/wait.h> +#include <unistd.h> 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) { |