Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, I considered asking here instead of SO because people here are more likely to be familiar with this stuff.

I'm currently using PHP to detect some generic stuff on the host OS. In this case, I'm trying to detect CPU vendor.

To do this, I have:

  • linux: execute('grep -m 1 vendor_id /proc/cpuinfo')
  • windows: getenv('PROCESSOR_IDENTIFIER')
  • osx: ???

OSX is indeed my problem. I don't have a test machine, and I refuse to run an illicit VM (I already am using 11 legit VMs).

So, since Apple makes it impossible to do this without spending nothing less than $500 to be able to run osx, I've decided to resort to someone else to help me achieve this.

I'd like the command to work on both PPC and Intel models.

Related Thread on SO again, I'm not able to run any of those commands.

share|improve this question

Try this from the terminal or execute as needed:

system_profiler|grep Processor


> dmourati$ system_profiler|grep Processor
>       Processor Name: Intel Core 2 Duo
>       Processor Speed: 2 GHz
>       Number Of Processors: 1
share|improve this answer
Sounds great! Can grep be made to read from after Processor Name: till the next newline? Also, if someone could test this on a PPC and verify that it works, it would be great. – Christian Jul 28 '11 at 6:57
system_profiler|grep Processor | sed 's/Processor Name: //' – Iain Jul 28 '11 at 7:10

A faster way then the previous post:

system_profiler SPHardwareDataType | grep Processor\ Name

That limits it to only scanning the hardware, which is faster than scanning the whole system.

You can also change the first command to system_profiler -xml SPHardwareDataType if you want to read it in as XML and parse it that way (which should be more stable if the output changes from version-to-version.

share|improve this answer
Thanks, SPHardwareDataType did some great improvement in speed. – Christian Jul 28 '11 at 7:42

I'm answering my question because I got to the best fit answer, but not without the help of the two people above. So, thanks a lot guys.

Note: There's an additional command, because I found out that on the old PPC version, there's no "Processor Name", but instead, it is "CPU Type". Command system_profiler SPHardwareDataType | grep CPU\ Type fixed the problem. I just switch to it if the suggested one doesn't yield results.

Here's the code:

// ...
case 'osx':
    // check on OSX
    $res=self::execute('system_profiler SPHardwareDataType | grep Processor\ Name');
    if($procid==''){ // for older PPC-based models
        $res=self::execute('system_profiler SPHardwareDataType | grep CPU\ Type');
// ...

// match vendor
if(strpos($procid,'intel')  !==false)return 'intel';
if(strpos($procid,'amd')    !==false)return 'amd';
if(strpos($procid,'ppc')    !==false)return 'ppc';
if(strpos($procid,'powerpc')!==false)return 'ppc';

Dependency Note

I'm using a custom function for executing commands. It returns an array of result, stdout, stderr among other things. In this case, only stdout is being used, so you can as well replace it with shell_exec().

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.