[英]How can I know if I am running in a 64bits or a 32bits linux from within a perl script?
I don't want to directly access the shell (for example to use uname). 我不想直接访问外壳程序(例如使用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. 一旦知道我在Linux上,我正在寻找一种快速检测架构的方法(仅当它是32位或64位时)。
There are 3 separate questions you could be asking: 您可能会问3个独立的问题:
Note for all that there's not a single magic "64-bit", there's lots of different things that could mean. 请注意,虽然没有一个魔术“ 64位”,但可能有很多不同的含义。
/proc/cpuinfo
contains this info in a hard to parse manner. - /proc/cpuinfo
以难以解析的方式包含此信息。 You basically need to have a table of what the different CPUs are. 基本上,您需要有一张有关不同CPU的表。 I believe you'll get numbers bigger than 32 in an "address sizes" if the kernel is 64-bit, though. 我相信,如果内核是64位的,那么“地址大小”中的数字将大于32。 use POSIX;
-我相信use POSIX;
and inspecting (POSIX::uname())[4]
is the canonical answer, but -d /lib64
, -d /usr/lib64
being true is also a good indicator. 并检查(POSIX::uname())[4]
是规范的答案,但-d /lib64
, -d /usr/lib64
为true也是一个很好的指示。 use Config;
- 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. 并查看$Config{archname}
, $Config{myarchname}
, $Config{use64bitint}
或Config中与您认为“ 64位”含义相符的其他变量。 perl -e 'use Config; print $Config{longsize}';
Will return 8 bytes on a 64 bit implementation of Perl, and 4 bytes on a 32 bit implementation of Perl. 在Perl的64位实现上将返回8个字节,在32位的Perl实现上将返回4个字节。
If you want to actually check the hardware, you'll have to either do a uname or check for something that only reasonably exists on a 64 bit machine (like /lib64). 如果您想实际检查硬件,则必须执行uname或检查仅在64位计算机上合理存在的某些内容(例如/ lib64)。 Note that it is often not very useful to know the hardware support for 64 bits if you are stuck in a 32 bit application. 请注意,如果您陷入32位应用程序中,那么了解64位的硬件支持通常不是很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.