diff --git a/toys/other/taskset.c b/toys/other/taskset.c index 6da9ec7da..aae8ce212 100644 --- a/toys/other/taskset.c +++ b/toys/other/taskset.c @@ -114,15 +114,26 @@ void taskset_main(void) void nproc_main(void) { unsigned i, j, nproc = 0; + DIR *dd; // This can only detect 32768 processors. Call getaffinity and count bits. - if (!toys.optflags && -1!=sched_getaffinity(getpid(), 4096, toybuf)) { + if (!toys.optflags && -1!=sched_getaffinity(getpid(), 4096, toybuf)) for (i = 0; i<4096; i++) if (toybuf[i]) for (j=0; j<8; j++) if (toybuf[i]&(1<d_name, "cpu", 3)) continue; + for (ss = de->d_name+3; isdigit(*ss); ss++); + if (!*ss) nproc++; + } + closedir(dd); + } - xprintf("%u\n", nproc); + xprintf("%u\n", nproc ? : 1); }