Re: How to determine if running on a 32 or 64 bits kernel ?



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 |
|------------------------------------/-------------------------------------|
.



Relevant Pages

  • 2.6.16.6 ( - 2.6.16.11 ) compile failure on an alpha
    ... When trying to compile 2.6.16.11 on an alpha I encountered a compile ... # Linux kernel version: 2.6.16.5 ... # PCCARD support ... # Device Drivers ...
    (Linux-Kernel)
  • New kernel trashed the audio!
    ... No usb support - despite having usb support in the kernel ... No networking support - despite having networking support in the kernel ... I'm considering switching to Suse instead, because the Debian pre kernels ... have a lacking support for my hardware and I find it very difficult to compile ...
    (Debian-User)
  • Re: [PATCH] kbuild: work around distcc/icecc madness
    ... Peter and I noticed that distcc and icecc based kernel compiles ... The root cause for this problem is the check for the CFI support in ... When distcc/icecc offload the compile to a remote ... # AX.25 network device drivers ...
    (Linux-Kernel)
  • Re: Help needed for RedHat Enterprise Linux 4.0 with Marvell Yukon GIgabit
    ... kernel and fin. ... Just get an appropriate kernel source and compile it. ... Simply get yourself a PROPER Ge card, one with existing kernel support, ... You want to compile a driver! ...
    (comp.os.linux.setup)
  • Re: Distributions
    ... | general there are a lot of packages for people to use. ... kernel, have to run on a multitude of different systems, they tend to be ... and slower than if you compile those packages, ... can have that stability with virtually any distro. ...
    (Debian-User)