Vincent Torri wrote: > I want to retrieve the number of active processors. I have found that > using sysconf(_SC_NPROCESSORS_ONLN) could do the trick, but i have > read somewhere > (http://forum.soft32.com/linux2/CPUs-machine-ftopict13343.html) that > it might not return the correct number of processors. > > My question is, on Solaris, is it safe to use sysconf() ? Or is there > a better solution ?
AFAIK the only "easy" way (e.g. without poking in the kernel data) is to use the |sysconf()| interface. Examples (I'm using ksh93 since it has a "getconf" builtin which has functionality which is a superset of { /usr/bin/getconf, /usr/bin/xpg4/getconf, /usr/bin/xpg6/getconf } and exposes the |sysconf()| interface for scripts): -- snip -- # list the number of "configured" CPUs # (this is the maximum number available to the current OS # instance, but note that this may change after a reboot) $ ksh93 -c 'getconf NPROCESSORS_CONF' 16 -- snip -- -- snip -- # list the number of "online" CPUs: # (this value is dynamic and may be changed by the admins, # system events (e.g. CPU/memory failure) and other things) $ ksh93 -c 'getconf NPROCESSORS_ONLN' 14 -- snip -- ---- Bye, Roland -- __ . . __ (o.\ \/ /.o) roland.mainz at nrubsig.org \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer /O /==\ O\ TEL +49 641 3992797 (;O/ \/ \O;)