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



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.


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 !)

regards



.



Relevant Pages

  • Re: Video editing in Linux?
    ... >30ukp, and even then a typical winmodem was 25ukp, so the difference ... of course Linux may deal with this alot ... Most notably the IDE drivers way exceed that of VIA's. ... So i would need to compile them? ...
    (alt.linux)
  • Re: Paying developers to get features faster
    ... existing Open Source, ... This is true even with the Linux Kernel compile. ... >compile is atleast a lot better than a screen full of warning messages. ...
    (comp.os.linux.development.system)
  • Re: Paying developers to get features faster
    ... existing Open Source, ... This is true even with the Linux Kernel compile. ... >compile is atleast a lot better than a screen full of warning messages. ...
    (comp.security.misc)
  • Re: Paying developers to get features faster
    ... existing Open Source, ... This is true even with the Linux Kernel compile. ... >compile is atleast a lot better than a screen full of warning messages. ...
    (comp.os.linux.security)
  • Re: Paying developers to get features faster
    ... existing Open Source, ... This is true even with the Linux Kernel compile. ... >compile is atleast a lot better than a screen full of warning messages. ...
    (comp.os.linux.misc)