top - 08:06:45 up 4 days, 18:50, 3 users, load average: 0.13, 0.31, 0.47 Tasks: 307 total, 1 running, 239 sleeping, 0 stopped, 0 zombie %Cpu(s): 8.3 us, 17.8 sy, 0.0 ni, 71.7 id, 0.1 wa, 0.0 hi, 2.1 si, 0.0 st KiB Mem : 16268580 total, 4063440 free, 1830428 used, 10374712 buff/cache KiB Swap: 3906556 total, 3905772 free, 784 used. 13538748 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1647 perry 20 0 1108788 104516 76212 S 11.1 0.6 3:13.87 Xorg 6168 perry 20 0 44228 3968 3272 R 11.1 0.0 0:00.05 top 1789 perry 20 0 4132128 266528 123144 S 5.6 1.6 3:09.14 gnome-shell 1835 perry 20 0 428252 7760 6312 S 5.6 0.0 0:04.20 ibus-daemon 1 root 20 0 225488 9260 6612 S 0.0 0.1 0:12.74 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.02 kthreadd 3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp 6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-kb 9 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq 10 root 20 0 0 0 0 S 0.0 0.0 0:00.09 ksoftirqd/0 ...Q: total tasks doesn't equal running + sleeping ?
A: top doesn't report every status, only a selected number from a larger list. There are more process states than "running" and "sleeping".
From man ps:
D uninterruptible sleep (usually IO) R running or runnable (on run queue) S interruptible sleep (waiting for an event to complete) T stopped by job control signal t stopped by debugger during the tracing W paging (not valid since the 2.6.xx kernel) X dead (should never be seen) Z defunct ("zombie") process, terminated but not reaped by its parentRef: https://unix.stackexchange.com/questions/420320/why-does-total-tasks-listed-in-top-command-output-not-equal-running-sleeping
$ ./cpu A & ./cpu B & [1] 31871 [2] 31872 A B A B A ... In another terminal window: $ top ... PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 31901 perry 20 0 4516 804 740 R 100.0 0.0 0:26.73 cpu 31902 perry 20 0 4516 792 728 R 100.0 0.0 0:26.71 cpu ... $ mpstat -P ALL 3 2 # average over 3 seconds, twice Linux 4.15.0-177-generic (zz) 09/02/2022 _x86_64_ (4 CPU) 07:18:06 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle 07:18:09 AM all 50.12 0.00 0.17 0.00 0.00 0.58 0.00 0.00 0.00 49.13 07:18:09 AM 0 0.00 0.00 0.00 0.00 0.00 1.97 0.00 0.00 0.00 98.03 07:18:09 AM 1 1.33 0.00 0.67 0.00 0.00 0.33 0.00 0.00 0.00 97.67 07:18:09 AM 2 100.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 07:18:09 AM 3 100.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 07:18:09 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle 07:18:12 AM all 50.08 0.00 0.08 0.00 0.00 0.58 0.00 0.00 0.00 49.25 07:18:12 AM 0 0.65 0.00 0.00 0.00 0.00 2.29 0.00 0.00 0.00 97.06 07:18:12 AM 1 0.33 0.00 0.33 0.00 0.00 0.33 0.00 0.00 0.00 99.00 07:18:12 AM 2 100.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 07:18:12 AM 3 100.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle Average: all 50.10 0.00 0.12 0.00 0.00 0.58 0.00 0.00 0.00 49.19 Average: 0 0.33 0.00 0.00 0.00 0.00 2.13 0.00 0.00 0.00 97.55 Average: 1 0.83 0.00 0.50 0.00 0.00 0.33 0.00 0.00 0.00 98.33 Average: 2 100.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Average: 3 100.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 $ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 1 Core(s) per socket: 4 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 158 Model name: Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz Stepping: 9 CPU MHz: 3327.177 CPU max MHz: 3500.0000 CPU min MHz: 800.0000 BogoMIPS: 6000.00 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 6144K NUMA node0 CPU(s): 0-3 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d $