473,573 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 8 '06 #1
8 6141
In article <44********@use net01.boi.hp.co m>,
dwelch91 <do**********@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 (je*@jes-2.demon.nl)

Jul 8 '06 #2
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
Jul 8 '06 #3
"MrJean1" <Mr*****@gmail. comwrote in message
news:11******** **************@ 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', '', '')
>>>

Jul 8 '06 #4
Jim Segrave wrote:
In article <44********@use net01.boi.hp.co m>,
dwelch91 <do**********@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

Jul 8 '06 #5
In article <44********@use net01.boi.hp.co m>,
dwelch91 <do**********@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 *).
Jul 10 '06 #6
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

Jul 10 '06 #7
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

Jul 10 '06 #8
In article <ma************ *************** ************@py thon.org>,
Robin Becker <ro***@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.
Jul 11 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1855
by: John Eric Hanson | last post by:
My company is considering a development path in which we develop code on 32 bit Windows machines to run remotely on 64 bit Linux machines. What could go wrong?
7
4938
by: Mauricio Tavares | last post by:
I just installed db2 8.1 workgroup server edition in a suse enterprise 9 linux box. The window in the end of the install tell me to run db2fs as a normal user. I do it: raubtest@db2:~>db2fs DB2JAVIT : RC = 9501 DB2INSTANCE : -2029059916 raubtest@db2:~> From the documentation, I was supposed to see a window where I could
0
1380
by: seb.haase | last post by:
Hi, I have ordered a new Athlon64 PC running linux x86_64. I'm using Pyro to communicate between python programs running on different machines. I know that, because Pyro's communication is based on pickle, that the different machines have to run the same Python (major) version: that is, it did not work after I just upgraded ONE machine from...
19
3793
by: llothar | last post by:
I must say i didn't expect this. I just did some measures on FreeBSD 6.2 with gcc 3.4.6 and there is absolutely no significant difference between 32 and 64 bit mode - neither in compilation speed, nor in speed of the compiled result. As a benchmark i took a bootstrap of the SmallEiffel Compiler (which has 38 files with around 100 kloc). The...
2
2160
by: M O J O | last post by:
(I'm using Visual Studio 2008) I want my new develloper pc to be Vista 64bit, but all my clients are so far 32bit (XP), so my questions are: 1) Is it possible for me to tell VS2008 that the output should be 32bit? That is devellop dotnet on a 64bit machine and output 32bit program? 2) When later this year, all my clients are updgraded...
0
2978
by: Leo Park | last post by:
Hello, guys. I want to compile 32bit *.c and *.cc files On 64bit x86_64 systems. But, it is not work. --------------------------------------------------------------------------------------------------------------- bmk_mgr@ikdp101: gcc --version gcc (GCC) 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)
1
3467
by: Morfys | last post by:
Hi, I would like to copy glibc/libgcc (in particular, libc.so. 6,libgcc_s.so.1) for a 32bit machine onto a 64bit machine. Would using the 32bit glibc/libgcc on the 64bit machine work? The reason I ask is that I've been getting the following error: Bin/libc.so.6: symbol _dl_out_of_memory, version GLIBC_PRIVATE not defined in file...
9
7230
by: Aditi | last post by:
I am working around a problem called Y2038 bug. http://groups.google.co.in/group/comp.unix.programmer/browse_thread/thread/a2f678e4f2761fb0/2816aaf1f50f863e?hl=en&lnk=st&q=time.h+64+bit+linux#2816aaf1f50f863e I am developing an application which need to be built both on windows and linux and used time_t, ctime, mktime, localtime and gmtime...
4
3292
by: legrape | last post by:
I am porting a piece of C code to 64bit on Linux. I am using 64bit integers. It is a floating point intensive code and when I compile (gcc) on 64 bit machine, I don't see any runtime improvement when optimizing -O3. If I construct a small program I can get significant (>4x) speed improvement using -O3 versus -g. If I compile on a 32 bit...
0
7694
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8065
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5593
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5291
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3732
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2213
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1303
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1041
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.