summaryrefslogtreecommitdiff
path: root/parallel.c
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-07-10 10:51:46 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-07-10 10:51:46 -0400
commitb5c8031c8f202c8140ee69c901c0e719a244aa77 (patch)
treeb6742cdc57a1a2218b3046cb5b1e7a36676a192d /parallel.c
parentab46fb8018f45a5584485edfd3c0caa82f3fd9b4 (diff)
downloadmoreutils-b5c8031c8f202c8140ee69c901c0e719a244aa77.tar.gz
use sysconf to determine number of processors
Diffstat (limited to 'parallel.c')
-rw-r--r--parallel.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/parallel.c b/parallel.c
index 0895c13..8045e22 100644
--- a/parallel.c
+++ b/parallel.c
@@ -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) {