How can I programmatically start a program in the 32 bits or 64 bits environment?

北慕城南 提交于 2019-12-12 08:59:08

问题


I have a binary that can be run in both 32 and 64 bits, that loads dynamic bundles for fiddling purposes. However, by default it runs on the 64 bits environment; so if I hit a 32-bits only bundle, dlopen fails.

It's easy to check for this beforehand, so all I really need is a way to choose whether to launch it in 32 bits or 64 bits. How can I programmatically do that? I'm open to anything Snow Leopard might support.


回答1:


In addition to what @GWW wrote, if you really want to do this programmatically, you can use posix_spawnattr_setbinpref_np to set the preferred CPU type and then use posix_spawn.

The CPU type is specified by cpu_type_t, which I believe is defined in #include <mach/machine.h>. But it may be safer to include #include <mach-o/arch.h>. See arch (3) manpage.




回答2:


This worked for me to launch python in 32-bit / 64-bit

arch -i386 python
Python 2.7 (r27:82500, Nov 10 2010, 22:46:43) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxint
2147483647

arch -x86_64 python
Python 2.7 (r27:82500, Nov 10 2010, 22:46:43) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxint
9223372036854775807


来源:https://stackoverflow.com/questions/5268957/how-can-i-programmatically-start-a-program-in-the-32-bits-or-64-bits-environment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!