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.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.
/proc/cpuinfocontains 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.use POSIX;and inspecting(POSIX::uname())[4]is the canonical answer, but-d /lib64,-d /usr/lib64being true is also a good indicator.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.