Re: How to determine if running on a 32 or 64 bits kernel ?
- From: phil-news-nospam@xxxxxxxx
- Date: 14 Feb 2008 17:55:14 GMT
On Thu, 14 Feb 2008 06:05:47 -0800 (PST) laurent.charmet@xxxxxxxxx wrote:
| On Feb 14, 3:42 pm, Bernhard Agthe <dark2s...@xxxxxxx> wrote:
|> laurent.char...@xxxxxxxxx wrote:
|> > I'm looking for an API or whatever to determine if kernel/os is 32 or
|> > 64 bits. It must be dynamic, because my binary can be compiled on a
|> > machine and run on another. So sizeof(void*) is useless since it give
|> > 4 if my program was compiled on a 32 bits linux, even if I run it on a
|> > 64 bits.
|>
|> > I do not find information in /proc nor in sysconf, sysinfo etc ...
|>
|> > The only solution, but very crappy is to make a popen of "file -b /usr/
|> > bin/file" and search for string "64" ...
|>
|> uname -a
|
| It's not very reliable. Uname -m give me "x86_64" on a 64 bits intel
| linux and "i686" on a 32 bits. But linux run on others platform not
| only intel. And how to know for PPC (first PPC was 32 bits) etc ... I
| do not want to use string.
I've dabbled around in computer architecture design (nothing ever built
but maybe some day I'll make an emulator). One design would support an
OS kernel that is fully capable of not only supporting both 32 bit and
64 bit requests through the very same ABI (not just 2 separate ABIs),
it would also support both big endian and little endian on that same
ABI.
My point is, why does it matter?
OK, there can be legitimate reasons to care about whether the kernel is
32 bit or 64 bit. But you might need to consider that there could be
other answers if you want this to be widely portable. One answer you
might get on some systems is "both". Another might be a number other
than 32 or 64. Maybe 48?
So consider what it is you will be trying to do with this information.
If it is being used to specifically call a syscall in the kernel that
is not implemented in too many runtime libraries (so you need to call
it directly), and need to know whether to call it as 32 bit or 64 bit,
maybe you should code your program to try it both ways.
As long as your program is compiled on a 32-bit environment and runs
in a 32-bit runtime environment, it should work for all runtime based
usage, transparent to what kernel is used.
|> sizeof (void*) will give you the size of a pointer to nothing ;-)
|>
|> A program compiled on 32 bit and linked with 32 bit libs will always be
|> 32 bit... Sizeof is usually evaluated during compile time.
|
| Yes It's what I say, we both agree on that.
|
| I'm a bit suprised that there is no simple solution to find this
| information. On AIX sysconf(_SC_AIX_KERNEL_BITMODE) give the answer.
| On HPUX it's about the same thing: sysconf(_SC_KERNEL_BITS). And I
| want to have this information without any privilege (do not want to
| open kernel for example !)
There's not necessarily a simple answer that can be expressed as "either
32 or 64". It does come down to why you need to know ... what are you
going to do with that knowledge? Do you need to know if 32 bit syscalls
work? What if the kernel can do both?
--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2008-02-14-1139@xxxxxxxx |
|------------------------------------/-------------------------------------|
.
- References:
- How to determine if running on a 32 or 64 bits kernel ?
- From: laurent . charmet
- Re: How to determine if running on a 32 or 64 bits kernel ?
- From: Bernhard Agthe
- Re: How to determine if running on a 32 or 64 bits kernel ?
- From: laurent . charmet
- How to determine if running on a 32 or 64 bits kernel ?
- Prev by Date: Re: USB device just moves
- Next by Date: Re: How to determine if running on a 32 or 64 bits kernel ?
- Previous by thread: Re: How to determine if running on a 32 or 64 bits kernel ?
- Next by thread: Re: How to determine if running on a 32 or 64 bits kernel ?
- Index(es):
Relevant Pages
|