Multiple CPUs
![]()
The Solaris code below calls the system API sysconf (i.e., system configuration) to request the count of on-line CPUs. This can be used to balance the number of threads or processes (i.e., fork()) created against system CPUs.
| #include <stdio.h> #include <unistd.h> main() { long NCPU = sysconf( _SC_NPROCESSORS_ONLN ); printf("There are %ld processors online\n", NCPU); } |
![]()
last update: 12/13/1999