Call the function uname()and check the return string machine, which will be x86_64for the 64-bit Intel platform.
One way to reverse the effect of use setarchis to reset the identity:
#include <stdio.h>
#include <sys/utsname.h>
#include <sys/personality.h>
int main()
{
struct utsname u;
personality(PER_LINUX);
uname(&u);
puts(u.machine);
return 0;
}
This shows the correct results when compiling in 32-bit mode and runs on a 64-bit system:
$ gcc -m32 -o u u.c
$ ./u
x86_64
$ setarch i686 ./u
x86_64
EDIT: fixed code for the opposite effect setarch.
Link .
source
share