I don’t want to directly access the shell (for example to use uname). I am looking for a fast-forward way to detect the architecture (only if it is 32 or 64 bits), once I know I am on linux.
Advertisement
Answer
There are 3 separate questions you could be asking:
Note for all that there’s not a single magic “64-bit”, there’s lots of different things that could mean.
- What’s the hardware? —
/proc/cpuinfo
contains this info in a hard to parse manner. You basically need to have a table of what the different CPUs are. I believe you’ll get numbers bigger than 32 in an “address sizes” if the kernel is 64-bit, though. - What’s the OS/kernel? — I believe
use POSIX;
and inspecting(POSIX::uname())[4]
is the canonical answer, but-d /lib64
,-d /usr/lib64
being true is also a good indicator. - Is this a 64-bit perl? —
use Config;
and look at$Config{archname}
,$Config{myarchname}
,$Config{use64bitint}
, or some other variable in Config that matches up to what you believe “64 bit” means.