jimwan
jimwan

Reputation: 1136

How can I check if the Mac OS is in 32 bit or 64 bit?

I want to determine if the Mac OS in 32 bit or 64 bit.

Who can write down the Perl script for me?

Upvotes: 2

Views: 583

Answers (4)

ikegami
ikegami

Reputation: 386501

It's not clear what you want.

To find the instruction set used for perl, you can use the following:

$ perl -V:myarchname
myarchname='x86_64-linux';

(As opposed to i686-linux.)

To find the size of integers used by perl, you can use the following:

  $ perl -V:ivsize
  ivsize='4';

(As opposed to 8.)

These values can be accessed from within Perl as follows:

use Config qw( %Config );
say $Config{myarchname};
say $Config{ivsize};

Upvotes: 3

David W.
David W.

Reputation: 107080

You can check the output of uname -a and see if it says i386 or x86_64 on the end:

#! /usr/bin/env perl

use strict;
use warnings;
use feature qw(say);
no warnings qw(uninitialized);

if (not -x "/usr/bin/uname") {
    say "Can't determine system bit mode: uname command not found";
}
else {
    chomp ( my $arch_type = qx(/usr/bin/uname -a) );
    if (not $arch_type) {
        say "Can't determine system bit mode";
    }
    elsif ($arch_type =~ /x86_64$/) {
        say "System is in 64 bit mode";
    }
    else {
        say "System is in 32 bit mode: $arch_type";
    }
}

Upvotes: 1

cypher
cypher

Reputation: 6992

I'm no perl programmer, but how about trying to add 1 to the maximum 32bit integer and cheching it against the overflown value? If it equals, you're on 32bit...

Upvotes: 2

Michael Dautermann
Michael Dautermann

Reputation: 89549

One possibility would be to call "arch".

A script I just quickly typed looks like this:

#!/usr/bin/perl -w
$arch=`arch`;
print $arch;

However, when I type in "arch" at my Terminal command line, I get an output of "i386". My Mac Pro tower is 64-bit capable (and some, if not all, apps run in 64-bit mode), so I'm not sure why I am not seeing "x86_64" output instead.

Upvotes: 1

Related Questions