Answers:
uname -a
会告诉您内核-末尾告诉您架构。
两个例子:
我的Mac:
Darwin Mac.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386
我的Dreamhost托管:
Linux ecco 2.6.24.5-serf-xeon-c6.1-grsec #1 SMP Tue Oct 7 06:18:04 PDT 2008 x86_64 GNU/Linux
i386 = 32位
x86_64 = 64位
uname -m
将为您提供编译内核的体系结构。如果可以打印i686
,则x86_64
假设您使用Intel / AMD芯片,则内核为32位,如果为64位,则为64位。
i386
在较旧的32位平台上运行(我什至看到过某些软件包已编译i586
-不确定该软件包是否会由发行uname
)
uname -m
为您提供了内核选择向特定进程公开的体系结构,而不是内核的本机体系结构。请参阅此链接。
uname -m
确实会报告真实的体系结构。如果不是这样,那么管理员很可能真的真的希望您相信您正在使用其他架构,并且最好的选择是接受他知道他在做什么。如果您是管理员,并且很麻烦,setarch
那么无论如何您都已经知道了。
setarch
,您可能会调用这样的脚本,却不知道它会导致uname -m
返回不同的内容。这类问题可能是,甚至可能是OP提出要求的原因。
init
认为它是32位的:这种情况是具有32位用户空间的64位内核。许多编译系统依赖于uname -m
确定编译器标志,例如GDB的标志,必须为其提供伪造的个性。但是,其他一些用户空间应用程序仍然希望知道其拥有哪种类型的内核(例如,出于某些低级需求),而与个性无关。
如果您想获得有关系统(CPU,内核和Core OS软件)的简单而详尽的报告,而不仅仅是内核,那么这里有一个小型的bash脚本,可以快速为您提供答案。
如果您对32位/ 64位CPU和S / W的特性了解足够,那就很方便了。如果您不太了解并且认为您的“系统”是32位还是64位,那么它将帮助您发现事实可能更加复杂(系统的某些部分可能是64位,而其他部分是32位)而不会引起您的困惑。
同样,此脚本(和答案)不是针对字面问题的:“我怎么知道我的Linux内核是以32位还是64位运行?” 但对于那些也想了解其CPU和核心OS SW的人。
这些是一个非常不寻常的情况的示例:
You have a 64 bit CPU
Your kernel reports that the architecture is 32 bit
Your /sbin/init process is 64 bit
Your C compiler is configured to produce 32 bit executables
You have a 64 bit CPU
Your kernel reports that the architecture is 32 bit
If you are not the admin he can make a 64bit kernel report 32bit (see man setarch)
In this case he has (because we have 64bit programs)
Your /sbin/init process is 64 bit
Most other core OS programs will probably be 64 bits also.
You may use the following command to check a specific program.
file -L /path/to/program
Your C compiler is configured to produce 32 bit executables
(Note that a 64bit compiler may be setup to produce 32bit code)
这4行提供了所有基本信息。
grep -w 'lm' /proc/cpuinfo > /dev/null && echo "You have a 64 bit CPU" || echo "You have a 32 bit CPU"
echo "Your kernel reports that the architecture is $(uname -m|sed -e 's/x86_64/64 bit/' -e 's/i.86/32 bit/')"
echo "Your /sbin/init process is $(file /sbin/init|sed -e 's/^.* \(32\|64\) bit.*$/\1bit/')"
echo "Your C compiler is configured to produce $(getconf LONG_BIT) bit executables"
该脚本有很多解释,如果您没有该主题的经验并且遇到特殊情况,该脚本将非常有用。
#!/bin/bash
# collect system info
grep -w 'lm' /proc/cpuinfo > /dev/null && CPU=64 || CPU=32
ARCH=$(uname -m|sed -e 's/x86_64/64/' -e 's/i.86/32/')
INIT=$(file -L /sbin/init|sed -e 's/^.* \(32\|64\)-bit.*$/\1/')
COMPILER=$(getconf LONG_BIT)
# if all values are the same we set UNIFORM="YES"
! echo "$CPU $ARCH $INIT $COMPILER" | grep -q "$CPU $CPU $CPU $CPU" && UNIFORM="NO" || UNIFORM="YES"
# report to the user
echo "You have a $CPU bit CPU"
echo "Your kernel reports that the architecture is $ARCH bit"
if [ "$UNIFORM" = "NO" ] && [ "$ARCH" = "32" ] ; then
echo " If you are not the admin he can make a 64bit kernel report 32bit (see man setarch)"
if [ "$INIT" = "64" ] || [ "$COMPILER" = "64" ] ; then
echo " In this case he has (because we have 64bit programs)"
else
echo " We don't see such signs so you most likely run a 32bit kernel"
echo " (A 64bit CPU can run 32bit kernels)"
fi
fi
echo "Your /sbin/init process is $INIT bit"
if [ "$CPU" = "64" ] ; then
echo " Most other core OS programs will probably be $INIT bits also."
echo " You may use the following command to check a specific program."
echo " file -L /path/to/program"
fi
if [ "$UNIFORM" = "NO" ] && [ "$INIT" = "32" ] ; then
echo " (Note that a 64bit kernel may start a 32bit init process)"
fi
echo "Your C compiler is configured to produce $COMPILER bit executables"
if [ "$UNIFORM" = "NO" ] && [ "$COMPILER" = "32" ] ; then
echo " (Note that a 64bit compiler may be setup to produce 32bit code)"
fi
如果您想了解更多信息,请从我获得最多信息的地方阅读这两页:a)/programming/246007/how-to-determine-whether-a-given-linux-is-32-位或64位 b)https://unix.stackexchange.com/a/134394/73271
如果只想查看正在运行的平台,则可以使用
uname -i
的受支持选项的完整列表uname
是
$ uname --help
Usage: uname [OPTION]...
Print certain system information. With no OPTION, same as -s.
-a, --all print all information, in the following order,
except omit -p and -i if unknown:
-s, --kernel-name print the kernel name
-n, --nodename print the network node hostname
-r, --kernel-release print the kernel release
-v, --kernel-version print the kernel version
-m, --machine print the machine hardware name
-p, --processor print the processor type or "unknown"
-i, --hardware-platform print the hardware platform or "unknown"
-o, --operating-system print the operating system
--help display this help and exit
--version output version information and exit
uname -i
prints GenuineIntel
,这并不是他真正想要的。
Unknown
在Mac上。
i386
在我的机器上打印!
CLFLUSHSIZE
没有告诉您有关处理器操作模式的任何信息。根据此答案,它是指最小的可刷新缓存单元。在您的情况下,缓存行以64字节为单位进行读写。
uname
从Wikipedia的示例表可以看出,输出的差异太大而无用。最可靠的方法getconf LONG_BIT
如Aquarius Power的答案所示。无论处理器体系结构如何,它都可以工作,因此x86上的ARM,Power或MIPS都可以在家工作。