I'm new to objective-c, for an academic reason I need to read CPU speed and H.D.D rpm
What is the simplest way to access some system setting i开发者_运维问答n objective-c or python
I can choose between objective-c and python for this project.
I think you would have to use a C++ module with Python to detect CPU speed or RPM of a hard drive. Calculate total CPU usage could help you here
I don't know anything about Obj-C, so couldn't tell you if it is possible with that language!
This can get the reported CPU speed for Windows 2000 and up by reading the registry using python:
import _winreg
key = _winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE,
r"HARDWARE\DESCRIPTION\System\CentralProcessor\0")
value, type = _winreg.QueryValueEx(key, "~MHz")
print 'CPU speed is:', value
I don't know how to do it for other operating systems nor how to get the HDD rpms though.
Checking CPU speed isn't really an Objective C thing, it is an OS thing. On OS X (and I assume iOS) you want to look at sysctlbyname(3) and the hw.cpufrequency property, something like:
int hz;
size_t hz_size = sizeof(hz);
int rc = sysctlbyname("hw.cpufrequency", &hz, &hz_size, NULL, 0);
if (0 == rc) {
fprintf(stderr, "Clockspeed is %d hz\n", hz);
}
I don't know a good way to get the RPM of a disk drive, but I do know a bad way. Parse the output of system_profiler, the info is in there (as "Rotational Rate"):
Hitachi HTS543232L9SA02: Capacity: 320.07 GB (320,072,933,376 bytes) Model: Hitachi HTS543232L9SA02 Revision: FB4AC50F Serial Number: (omitted) Native Command Queuing: Yes Queue Depth: 32 Removable Media: No Detachable Drive: No BSD Name: disk0 Rotational Rate: 5400 Medium Type: Rotational Partition Map Type: GPT (GUID Partition Table) S.M.A.R.T. status: Verified Volumes: Macintosh HD: Capacity: 319.73 GB (319,728,959,488 bytes) Available: 12.4 GB (12,397,940,736 bytes) Writable: Yes File System: Journaled HFS+ BSD Name: disk0s2 Mount Point: /
There is likely a better abstraction to use, I just don't know it.
精彩评论