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



On Fri, 15 Feb 2008 06:00:44 -0800 (PST) laurent.charmet@xxxxxxxxx wrote:

| I probably not well exposed my need, but I have a small soft who run
| on many machine/os (aix, hpux, irix, linux, bsd/mac, tru64,
| win32, ...). And it display system info (memory, swap, cpu name, cpu
| freq, number of cpu, os name), compilation option, ILP.
|
| example:
|
| E:\FF\Bin>tina_bench -bench info
| -------------- Host name: grossebaf -----------
| Version: 4.2.0 SP0 patch 2998 Build 7 (Feb 15 2008)
| OS name=Windows Server 2003, OS release=Service Pack 2, OS
| version=5.2.3790, Architecture name=Intel
| 2 X Intel(R) Pentium(R) 4 CPU 2.80GHz @ 2793 Mhz
| Mem: 1024 MB, Swap: 1450 MB
| Kernel=32 bits, Software=32 bits, Endian=little-endian, Data
| Model=ILP32
|
| Sorry if it's cut&paste from my wintel office PC lol !
|
|
| And for the last time, uname is NOT the solution:
| uname -m on a Linux on powerpc give me PPC64. It's a 64 bits OS/
| kernel ? NO ! it's a 32 bits because all system binaries are 32 bits
| ELF

If you want the capability of the kernel, uname is the best solution.

If you want the capability of the runtime library the program is
running under, then things like sizeof(void*) tell you because it
is the same as compiled with. Specifically, if the program CAN
RUN AT ALL it has a run time environment compatible with the one
it was compiled with.

If you want to have something understand other possible capabilities
of the system outside the scope of what the program happens to be
running under at that moment (for example to select the best files
to install), that will be a much more complex task because there are
no simple answers to the question.


| It's incredible that it's impossible to determine if os/kernel is 32
| or 64 bits (or 128 !) with a small call.

If you want to determine that of the KERNEL then uname is best. You do
need to keep in mind that the possible answers are NOT AS SIMPLE as
this statement suggests. A function call that does something like
return an integer with a value of 32 or 64 or 128 cannot convey the
real possible scope of possible kernels that it might encounter.

Again, the real answers may not be as simple as the questions imply.
While it could be a lot of work to build a complex multi interface
kernel, it is very easy to set up multiple run time environments on
the same system.

But if the question is what architecture and subarchitecture the kernel
as been built as (since presently there is no multi interface kernel),
then uname tells you that.

--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2008-02-15-1001@xxxxxxxx |
|------------------------------------/-------------------------------------|
.



Relevant Pages

  • Linux 2.6 Kernel Capability LSM Module Local Privilege Elevation
    ... Vulnerable: Linux kernel 2.6.* ... When POSIX Capability LSM module isn't compiled into kernel, ... Capability module into kernel, all existed normal users processes will have ... total Capability privileges of superuser. ...
    (Bugtraq)
  • Re: [RFC] [PATCH] file posix capabilities
    ... bitfield are defined to be zero. ... bit that the kernel doesn't recognize, ... It's extensible (as new capability bits are added, ... not-present bytes and therefore assumed to be zero. ...
    (Linux-Kernel)
  • Re: [PATCH] ppc64: Fix PER_LINUX32 behaviour
    ... actually compile up ppc64 kernels from time to time... ... If uname wants to make it clear that uname has ... > own without asking the kernel what the kernel is. ... system calls were ignoring the personality and just returning what was ...
    (Linux-Kernel)
  • Re: change kernel name
    ... It turns out that you can easily change the kernel name, version, ... # ./tester SYSNAME foo ... Can't open device file, UNAME ...
    (Linux-Kernel)
  • Re: capget() overflows buffers.
    ... |> The kernel is not crashing, ... It's about app security. ... Not to pick holes in your argument, but libcap *has* always been there. ... Remain source compatible with 32-bit raw legacy capability support. ...
    (Linux-Kernel)