2 * Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
4 * Licensed under GPLv2, see LICENSE in this source tree
7 //config: bool "nproc (248 bytes)"
10 //config: Print number of CPUs
12 //applet:IF_NPROC(APPLET_NOFORK(nproc, nproc, BB_DIR_USR_BIN, BB_SUID_DROP, nproc))
14 //kbuild:lib-$(CONFIG_NPROC) += nproc.o
16 //usage:#define nproc_trivial_usage
18 //TODO: "[--all] [--ignore=N]"
19 //usage:#define nproc_full_usage "\n\n"
20 //usage: "Print number of CPUs"
25 int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
26 int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
28 unsigned long mask[1024];
29 unsigned i, count = 0;
33 //if --all, count /sys/devices/system/cpu/cpuN dirs, else:
35 if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) {
36 for (i = 0; i < ARRAY_SIZE(mask); i++) {
37 unsigned long m = mask[i];
47 printf("%u\n", count);