discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSProcessInfo -processorCount, -activeProcessorCount, -physicalMemor


From: David Chisnall
Subject: Re: NSProcessInfo -processorCount, -activeProcessorCount, -physicalMemory
Date: Thu, 13 Nov 2008 13:00:23 +0000

On 13 Nov 2008, at 12:49, Pete French wrote:

This too is a system specific solution, but at least we use glibc
instead of doing the parsing ourselves. This should save us the problem
of adopting to a new kernel every time.

We still will need different solutions for non-Linux systems.

isn;'t there some kind of standard for these things ? Over in FreeBSD
land /proc has been depracated for a couple of years and no longer
appears by default. I dont ever look at this part of the kernel,
but I wwas under the imppression there was a rough set of standardised
calls to replace all this on Unix/BSD at least. So we could use /proc
on Linux/Plan9 style things and the aalternative on Unix/BSD system
maybe ?

Ooops - my last reply was sent just to Fred, not to the list.

In *BSD these are all done via sysctls, which are a much cleaner interface than parsing a big blob of text (which, in Linux's case, has a different format on different architectures). In Étoilé's SystemConfig framework you will find a set of simple wrappers that call a sysctl by name and return either an NSString or an integer:

http://svn.gna.org/viewcvs/etoile/stable/Frameworks/SystemConfig/Source/TRSysctlByName.h?rev=3718&view=auto

There are examples using these to find the amount of memory, CPU name, and CPU speed for various platforms here:

http://svn.gna.org/viewcvs/etoile/stable/Frameworks/SystemConfig/Source/

There is also a Solaris implementation (which uses different interfaces) in the same directory.

Getting the number of CPUs is just a matter of using a different sysctl. On FreeBSD, OpenBSD, and Darwin, "hw.ncpu" gives the total number of CPUs. On FreeBSD, kern.smp.cpus seems to give the number of active CPUs and on Darwin hw.activecpu does the same.

David



reply via email to

[Prev in Thread] Current Thread [Next in Thread]