Saturday, August 23, 2008

How to find out if OS is 64 bit or 32 bit......

1. If it were windows its the most simple thing is to see into the properties of the system. Obviously these values shown in the property list are taken from the registry. The info is listed in the
HKEY_LOCAL_MACHINE/HARDWARE/Description.
2. On a linux machine if you login into the machine(may be using a putty), the description of the machine is displayed. else a simple command uname -a should do.
3.On an AIX machine things become a bit bitter. The uname thing doesnt work. So we have another command there which is:
bootinfo -K (It gives the kernal info if its 32 bit or 64 bit).
Now theres a link to the most basic commands in AIX,which shud'nt be left at home when u r at work on AIX machine. Link is: http://www.ibm.com/developerworks/aix/library/au-dutta_cmds.html

Ok, back to our topic of discussion.

4. Solaris gives answer to the same question by the command:
/usr/bin/isainfo -kv

5. Now if the problem is somehow to identify inside a code what platform its running on and then if its 32 bit or 64 bit might be difficult.
Ok, here we will make a simple assumption. And this is what makes things different for this blog...
we have a small program.A C code:

#include
printf("the integer pointer is of size %d",sizeof(int *));

Now the integer pointer for a 32 bit compiler will be 4 byte size.. and for a 64 byte compiler.
Again we are not addressing here the question we arose earlier that is if the system is 32 bit or 64 bit. but we have talked if the compiler is 32 bit or 64 bit.

So if the answer we get here is 8 , its sure to be a 64 bit compiler which will run on a 64 bit system. But if we get the answer as 4, we are not really sure of.

------------------------------------------------------------------------------------------------
Editing this information after i got some new info..... regarding the discussion

so write any C program anywhere in the system..
Then just compile it. as gcc filename.c
And then do readelf -a a.out

This gives the whole description of the symbol table. and the register usage. Just look at the address of any register there. You will get 0x<16> ... here is an answer.. each char in hex needs 4 bits to represent . If its 16digit no, this is 64 bit addressable memory. means a 64 bit machine... so the compiler helped in tracing the architecture.
Though i checked it in a Linux 32 and 64 bit machine.. it should do with all unix version.. :)



No comments: