我怎么能从壳内告诉壳处于什么模式?

我已经试着查看了平台模块,但它似乎只告诉您“用于可执行文件的位架构和链接格式”。我的二进制文件被编译为64位(我在OS X 10.6上运行),所以它似乎总是报告64位,即使我使用这里描述的方法强制32位模式。


当前回答

对于非编程解决方案,请查看活动监视器。它将64位进程的体系结构列为“Intel(64位)”。

其他回答

在我的Centos Linux系统上,我做了以下操作: 1)启动Python解释器(我使用2.6.6) 2)运行如下代码:

import platform
print(platform.architecture())

它给了我

(64bit, 'ELF')

尝试使用ctypes来获取void指针的大小:

import ctypes
print ctypes.sizeof(ctypes.c_voidp)

32位是4位,64位是8位。

平台架构不是可靠的方法。 相反,我们:

$ arch -i386 /usr/local/bin/python2.7
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform, sys
>>> platform.architecture(), sys.maxsize
(('64bit', ''), 2147483647)
>>> ^D
$ arch -x86_64 /usr/local/bin/python2.7
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform, sys
>>> platform.architecture(), sys.maxsize
(('64bit', ''), 9223372036854775807)

Windows 10操作系统

打开cmd终端,输入如下图所示的>python启动python解释器

如果解释器信息在开始时包含AMD64,则为64位,否则为32位。

打开python控制台:

import platform
platform.architecture()[0]

它应该显示'64bit'或'32bit'根据您的平台。

或者(对于OS X二进制文件):

import sys
sys.maxsize > 2**32 
# it should display True in case of 64bit and False in case of 32bit