4

Here is output from nproc vs nproc --all and other command found on internet. I still cannot understand why. It is a QEMU\KVM VM with CentOS 6.5 running undre other CentOS 6.5.

Below are outputs from some other commands:

[root@h1-nms ~]# nproc
1
[root@h1-nms ~]# nproc --all
3
[root@h1-nms ~]# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                3
On-line CPU(s) list:   0-2
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             3
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 13
Stepping:              3
CPU MHz:               2194.710
BogoMIPS:              4389.42
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
NUMA node0 CPU(s):     0-2
[root@h1-nms ~]# getconf _NPROCESSORS_ONLN
3
[root@h1-nms ~]# cat /proc/$$/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            10485760             unlimited            bytes
Max core file size        unlimited            unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             32000                32000                processes
Max open files            64000                64000                files
Max locked memory         65536000             65536000             bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       191509               191509               signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us
[root@h1-nms ~]# grep "" /sys/devices/system/cpu/cpu*/online
/sys/devices/system/cpu/cpu1/online:1
/sys/devices/system/cpu/cpu2/online:1
[root@h1-nms ~]# uname -a
Linux h1-nms 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@h1-nms ~]# cat /etc/*-release
CentOS release 6.5 (Final)
CentOS release 6.5 (Final)
CentOS release 6.5 (Final)
[root@h1-nms ~]#
4

As indicated in Kusalananda’s answer, nproc distinguishes between the number of CPUs available to the current process, and the overall number of CPUs.

On Linux systems, the CPUs available to the current process, when OpenMP isn’t involved, is determined by the process’s affinity mask. To see that, run taskset:

taskset -p $$

or schedtool:

schedtool $$

(taskset is part of the util-linux package, and should be installed by default; schedtool is its own package, and might need to be installed if you want to use it.)

In your case this should show that your shell is limited to a single processor, which is why nproc outputs 1.

  • thx! How can I learn who & where set this mask? Indeed it is 1 ("pid 12308's current affinity mask: 1") and on very similar machine (redundant one) it is 3 – ALZ Mar 2 '18 at 15:39
  • I don’t think there’s any easy way of determining where the mask is set; look for taskset in shell configuration scripts maybe... – Stephen Kitt Mar 2 '18 at 15:43
2

From the top of the nproc manual:

Print the number of processing units available to the current process, which may be less than the number of online processors.

then

--all

print the number of installed processors

The GNU info documentation says a tiny bit more:

Print the number of processing units available to the current process, which may be less than the number of online processors. If this information is not accessible, then print the number of processors installed. If the OMP_NUM_THREADS or OMP_THREAD_LIMIT environment variables are set, then they will determine the minimum and maximum returned value respectively. The result is guaranteed to be greater than zero.

and

--all

Print the number of installed processors on the system, which may be greater than the number online or available to the current process. The OMP_NUM_THREADS or OMP_THREAD_LIMIT environment variables are not honored in this case.

  • on centos7, my manpage for nproc doesn't talk about the environment variables :(. even though i tested and the environment variables definitely change the value output from nproc. – Trevor Boyd Smith May 27 at 13:36
  • @TrevorBoydSmith It didn't on the system I tested either. This is why I consulted the GNU info documentation (info nproc). – Kusalananda May 27 at 13:38
  • ah thanks for the tip about using info nproc. i never open info documentation except as a last resort... and even then it always leaves a bad taste and slows me down terribly. – Trevor Boyd Smith May 27 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.