开发者

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

I have a binary that can be run in both 32 and 64 bits, that loads dynamic bundles for fiddling purposes. Howeve开发者_运维百科r, 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.


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜