Detecting 64bit vs. 32bit Linux

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dwelch91

    #1

    Detecting 64bit vs. 32bit Linux

    I need to detect whether the operating system I am running on (not the
    Python version) is 64bit or 32bit. One requirement is that I need to
    include support for non-Intel/AMD architectures.

    The 2 ways I have thought detecting 64bit are:

    1. struct.calcsize ("P") == 8
    2. '64' in os.uname()[4]

    I'm not convinced that either one of these is really adequate. Does
    anybody have any other ideas on how to do this?

    Thanks,

    Don


  • Jim Segrave

    #2
    Re: Detecting 64bit vs. 32bit Linux

    In article <44aea052$1@use net01.boi.hp.co m>,
    dwelch91 <donald.welch@h p.comwrote:
    >I need to detect whether the operating system I am running on (not the
    >Python version) is 64bit or 32bit. One requirement is that I need to
    >include support for non-Intel/AMD architectures.
    >
    >The 2 ways I have thought detecting 64bit are:
    >
    >1. struct.calcsize ("P") == 8
    >2. '64' in os.uname()[4]
    >
    >I'm not convinced that either one of these is really adequate. Does
    >anybody have any other ideas on how to do this?
    Does sys.maxint give what you need?

    I think for most machines this will give you the answer you are
    looking for - either 2**31 -1 for a 32 bit version or 2**63-1 for a 64
    bit version. It's set up during the configure phase of building python

    If you want to detect a 64bit OS running a compatibility mode for a 32
    bit version of Python, then you'll need to figure out how to build and
    incorporate a Python extension which can detect this situation




    --
    Jim Segrave (jes@jes-2.demon.nl)

    Comment

    • MrJean1

      #3
      Re: Detecting 64bit vs. 32bit Linux

      Try function architecture() from the platform module in Python 2.3 and
      2.4. The first item of the returned tuple shows whether the underlying
      system is 64-bit capable.

      Here is what it returns on RedHat Fedora Core 2 Linux on Opteron:
      >>platform.arch itecture()
      ('64bit', 'ELF')
      >>platform.unam e()
      ('Linux', 'XXXX', '2.6.16.14', '#1 SMP Sat Jul 1 14:09:18 CDT 2006',
      'x86_64', 'x86_64')


      On RedHat Fedora Core 2 on Pentium 4:
      >>platform.arch itecture()
      ('32bit', 'ELF')
      >>platform.unam e()
      ('Linux', 'XXXX', '2.6.10-1771-FC2', '#1 Mon Mar 28 00:50:14 EST 2005',
      'i686', 'i686')


      And on MacOS X 10.3.9 G4:
      >>platform.arch itecture()
      ('32bit', '')
      >>platform.unam e()
      ('Darwin', 'XXXX', '7.9.0', 'Darwin Kernel Version 7.9.0: Wed Mar 30
      20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC ', 'Power
      Macintosh', 'powerpc')


      /Jean Brouwers



      dwelch91 wrote:
      I need to detect whether the operating system I am running on (not the
      Python version) is 64bit or 32bit. One requirement is that I need to
      include support for non-Intel/AMD architectures.
      >
      The 2 ways I have thought detecting 64bit are:
      >
      1. struct.calcsize ("P") == 8
      2. '64' in os.uname()[4]
      >
      I'm not convinced that either one of these is really adequate. Does
      anybody have any other ideas on how to do this?
      >
      Thanks,
      >
      Don

      Comment

      • Paul McGuire

        #4
        Re: Detecting 64bit vs. 32bit Linux

        "MrJean1" <MrJean1@gmail. comwrote in message
        news:1152378882 .958222.281730@ m73g2000cwd.goo glegroups.com.. .
        Try function architecture() from the platform module in Python 2.3 and
        2.4. The first item of the returned tuple shows whether the underlying
        system is 64-bit capable.
        >
        Here is what it returns on RedHat Fedora Core 2 Linux on Opteron:
        >
        >platform.archi tecture()
        ('64bit', 'ELF')
        >platform.uname ()
        ('Linux', 'XXXX', '2.6.16.14', '#1 SMP Sat Jul 1 14:09:18 CDT 2006',
        'x86_64', 'x86_64')
        >
        >
        On RedHat Fedora Core 2 on Pentium 4:
        >
        >platform.archi tecture()
        ('32bit', 'ELF')
        >platform.uname ()
        ('Linux', 'XXXX', '2.6.10-1771-FC2', '#1 Mon Mar 28 00:50:14 EST 2005',
        'i686', 'i686')
        >
        >
        And on MacOS X 10.3.9 G4:
        >
        >platform.archi tecture()
        ('32bit', '')
        >platform.uname ()
        ('Darwin', 'XXXX', '7.9.0', 'Darwin Kernel Version 7.9.0: Wed Mar 30
        20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC ', 'Power
        Macintosh', 'powerpc')
        >
        >
        One Windows XP 32-bit, I get:
        >>import platform
        >>platform.arch itecture()
        ('32bit', 'WindowsPE')
        >>platform.unam e()
        ('Windows', 'awa1', 'XP', '5.1.2600', '', '')
        >>>

        Comment

        • Robert Kern

          #5
          Re: Detecting 64bit vs. 32bit Linux

          Jim Segrave wrote:
          In article <44aea052$1@use net01.boi.hp.co m>,
          dwelch91 <donald.welch@h p.comwrote:
          >I need to detect whether the operating system I am running on (not the
          >Python version) is 64bit or 32bit. One requirement is that I need to
          >include support for non-Intel/AMD architectures.
          >>
          >The 2 ways I have thought detecting 64bit are:
          >>
          >1. struct.calcsize ("P") == 8
          >2. '64' in os.uname()[4]
          >>
          >I'm not convinced that either one of these is really adequate. Does
          >anybody have any other ideas on how to do this?
          >
          Does sys.maxint give what you need?
          >
          I think for most machines this will give you the answer you are
          looking for - either 2**31 -1 for a 32 bit version or 2**63-1 for a 64
          bit version. It's set up during the configure phase of building python
          No. Some 64-bit systems (notably Win64) leave C longs as 32-bit. This is known
          as the LLP64 data model.

          --
          Robert Kern

          "I have come to believe that the whole world is an enigma, a harmless enigma
          that is made terrible by our own mad attempt to interpret it as though it had
          an underlying truth."
          -- Umberto Eco

          Comment

          • Lawrence D'Oliveiro

            #6
            Re: Detecting 64bit vs. 32bit Linux

            In article <44aea052$1@use net01.boi.hp.co m>,
            dwelch91 <donald.welch@h p.comwrote:
            >I need to detect whether the operating system I am running on (not the
            >Python version) is 64bit or 32bit. One requirement is that I need to
            >include support for non-Intel/AMD architectures.
            The standard C way would be to check sizeof(void *).

            Comment

            • Robin Becker

              #7
              Re: Detecting 64bit vs. 32bit Linux

              Michael Yanowitz wrote:
              .......
              >
              >I need to detect whether the operating system I am running on (not the
              >Python version) is 64bit or 32bit. One requirement is that I need to
              >include support for non-Intel/AMD architectures.
              >
              The standard C way would be to check sizeof(void *).
              so on those old ARM RISC OSes with 32 bit arithmetic would I get sizeof(void *)
              == 4 when the address bus was 26 bits wide? Seems a bit naive to assume the
              address bus will always be the same width as the registers, but I guess the
              compilers have to do something.

              I seem to remember some compilers allowing pure 32 bit addressing on 8088
              machines (with 16 bit registers), but I think the M$ compilers all had near and
              far pointer mechanisms to help you get confused.
              -mumbling-ly yrs-
              Robin Becker

              Comment

              • Robert Kern

                #8
                Re: Detecting 64bit vs. 32bit Linux

                Michael Yanowitz wrote:
                The one thing I observed (just an observation) is that:
                a) on 32-bit machines:
                sizeof(int) = 32
                sizeof(long) = 32
                b) on 64-bit machines:
                sizeof(int) = 32
                sizeof(long) = 64
                >
                This in C and Python.
                As I've said previously in this thread, not all systems work like that.
                Specifically, on Win64 sizeof(long) == 32.

                --
                Robert Kern

                "I have come to believe that the whole world is an enigma, a harmless enigma
                that is made terrible by our own mad attempt to interpret it as though it had
                an underlying truth."
                -- Umberto Eco

                Comment

                • Lawrence D'Oliveiro

                  #9
                  Re: Detecting 64bit vs. 32bit Linux

                  In article <mailman.7974.1 152537684.27775 .python-list@python.org >,
                  Robin Becker <robin@reportla b.comwrote:
                  >Michael Yanowitz wrote:
                  >......
                  >>
                  >>I need to detect whether the operating system I am running on (not the
                  >>Python version) is 64bit or 32bit. One requirement is that I need to
                  >>include support for non-Intel/AMD architectures.
                  >>
                  >The standard C way would be to check sizeof(void *).
                  >so on those old ARM RISC OSes with 32 bit arithmetic would I get sizeof(void
                  >*)
                  >== 4 when the address bus was 26 bits wide?
                  And the original 68000-based Macs where you would get the same
                  sizeof(void *), but the address bus was only 24 bits wide. Nevertheless,
                  you were supposed to pretend that addresses were a full 32 bits in size.
                  The programs that didn't got into trouble later.

                  Comment

                  Working...