Lm_sensors是一个 命令 行工具,用于显示所有芯片传感器数据的当前读数,包括CPU温度。默认情况下,Ubuntu LInux没有安装Lm_Sensors,因此,我们必须自己安装它们。
bob@bob-PC:~$ sudo apt install lm-sensors
检测硬件
接下来,我们需要检测安装在电脑上的硬件监控芯片。现在我们可以开始检测电脑的硬件传感器了:
bob@bob-PC:~$ sudo sensors-detect
# sensors-detect revision 6284 (2015-05-31 14:00:33 +0200)
# System: VMware, Inc VMware Virtual Platform [None]
# Board: Intel Corporation 440BX Desktop Reference Platform
# Kernel: 4150-30Ubuntu-generic x86_64
# Processor: Intel(R) Core(TM) i7-8700 CPU @ 320GHz (6/158/10)
This program will help you determine which kernel modules you need
to load to use lm_sensors most effectively It is generally safe
and recommended to accept the default answers to all questions,
unless you know what you're doing
Some south bridges, CPUs or memory controllers contain embedded sensors
Do you want to scan for them This is totally safe (YES/no): yes
Silicon Integrated Systems SIS5595 No
VIA VT82C686 Integrated Sensors No
VIA VT8231 Integrated Sensors No
AMD K8 thermal sensors No
AMD Family 10h thermal sensors No
AMD Family 11h thermal sensors No
AMD Family 12h and 14h thermal sensors No
AMD Family 15h thermal sensors No
AMD Family 16h thermal sensors No
AMD Family 17h thermal sensors No
AMD Family 15h power sensors No
AMD Family 16h power sensors No
Intel digital thermal sensor Success!
(driver `coretemp')
Intel AMB FB-DIMM thermal sensor No
Intel 5500/5520/X58 thermal sensor No
VIA C7 thermal sensor No
VIA Nano thermal sensor No
Some Super I/O chips contain embedded sensors We have to write to
standard I/O ports to probe them This is usually safe
Do you want to scan for Super I/O sensors (YES/no): yes
显示cpu温度
可以通过一下命令查看温度数据了:
bob@bob-PC:~$ sensors
iwlwifi_1-virtual-0
Adapter: Virtual device
temp1: +330°C
pch_skylake-virtual-0
Adapter: Virtual device
temp1: +385°C
BAT0-acpi-0
Adapter: ACPI interface
in0: +1245 V
coretemp-isa-0000
Adapter: ISA adapter
Package id 0: +390°C (high = +1000°C, crit = +1000°C)
Core 0: +390°C (high = +1000°C, crit = +1000°C)
Core 1: +380°C (high = +1000°C, crit = +1000°C)
thinkpad-isa-0000
Adapter: ISA adapter
fan1: 0 RPM
temp1: +380°C
temp2: N/A
temp3: +00°C
temp4: +00°C
temp5: +00°C
temp6: +00°C
temp7: +00°C
temp8: +00°C
BAT1-acpi-0
Adapter: ACPI interface
in0: +1249 V
acpitz-acpi-0
Adapter: ACPI interface
temp1: +380°C (crit = +1280°C)
还可以使用watch命令实时关注:
bob@bob-PC:~$ watch sensors
使用图形化工具psensor显示cpu温度
使用Psensor,您可以检查以下各项:
主板、CPU传感器和NVidia GPU的温度
硬盘驱动器的温度
风扇的转速
监视CPU使用情况
最新版本的Psensor还为Ubuntu提供了一个applet指示器,因此在Ubuntu上更容易监控硬件温度。您可以选择在顶部面板中显示温度。它甚至可以在温度超过极限时发送桌面通知。
我们可以使用下面的命令安装Psensor:
bob@bob-PC:~/Desktop$ sudo apt install -y psensor
打开ubuntu的launchpad,在里面找到psensor,打开该应用就可以看到多个传感器:
使用图形化工具hardinfo
Hardinfo是Linux中用于在图形化界面中显示硬件信息的工具。可以使用它检测cpu的温度。以下命令安装hardinfo:
bob@bob-PC:~/Desktop$ sudo apt install hardinfo
# 运行一下命令打开hardinfo
bob@bob-PC:~/Desktop$ sudo hardinfo
总结
在本教程中,我们将学习如何从命令行和桌面获取Ubuntu Linux上的CPU温度。
耐心看看啊,运行通过啦,希望对你有帮助啊!
#include<stdioh>
unsigned int veax;
unsigned int vebx;
unsigned int vedx;
unsigned int vecx;
//执行CPUID指令
void cpuid(unsigned int veax1)
{
_asm{
mov eax,veax1
cpuid
mov veax,eax
mov vebx,ebx
mov vecx,ecx
mov vedx,edx
}
}
//做移位 *** 作,把寄存器中的ASCII码,以字符形式输出
void LeftMove(unsigned int var)
{
printf("%c",var);
for(int i=0;i<3;i++)
{
var=(var>>;
printf("%c",var);
}
}
//做移位 *** 作,把寄存器中的值以“%d”形式输出
void LM(unsigned int var)
{
printf("%d",var);
for(int i=0;i<3;i++)
{
var=(var>>;
printf("%d",var);
}
}
//得到CPU的生产厂商(当EAX值为0时),依次存放在EBX,EDX,ECX中
void getCpuName()
{
cpuid(0);
LeftMove(vebx);
LeftMove(vedx);
LeftMove(vecx);
printf("\
";
}
//得到CPU的商标,当EAX中的值为0x80000003和0x80000004时分别返回16个字符,组成商标
//依次存放在EAX,EBX,ECX,EDX中
void getCpuBrand()
{
for(int j=0;j<2;j++)
{
cpuid(0x80000003+j);
LeftMove(veax);
LeftMove(vebx);
LeftMove(vecx);
LeftMove(vedx);
}
printf("\
";
}
//获得CPU的特性,参数是eax = 1,返回值放在edx和ecx,通过验证edx或者ecx的某一个bit,
//可以获得CPU的一个特性是否被支持。比如说,edx的bit 32代表是否支持MMX,
//edx的bit 28代表是否支持Hyper-Threading,ecx的bit 7代表是否支持speed sted。
void getCpuFeature()
{//由于特性太多,无法一一编写,需要的时候再写,方法是一样的。
}
//获得CPU序列号,获得序列号需要两个步骤,首先用eax = 1做参数,返回的eax中存储序列号的高两个WORD。
//用eax = 3做参数,返回ecx和edx按从低位到高位的顺序存储前4个WORD。
void getCpuSeris()
{
cpuid(1);
LM(veax);
cpuid(3);
LM(vecx);
LM(vedx);
printf("\
";
}
void main()
{
getCpuName();
getCpuBrand();
getCpuSeris();
}
可以直接使用top命令后,查看%MEM的内容。可以选择按进程查看或者按用户查看,如想查看oracle用户的进程内存使用情况的话可以使用如下的命令:(1)top top命令是Linux下常用的性能分析工具
查看CPU信息
cat /proc/cpuinfo
显示当前硬件信息
sudo lshw
获取CPU序列号或者主板序列号
#CPU ID
sudo dmidecode -t 4 | grep ID
#Serial Number
sudo dmidecode | grep Serial
#CPU
sudo dmidecode -t 4
#BIOS
sudo dmidecode -t 0
#主板:
sudo dmidecode -t 2
#OEM:
sudo dmidecode -t 11
显示当前内存大小
free -m |grep "Mem" | awk '{print $2}'
查看硬盘温度
sudo apt-get install hddtemp
sudo hddtemp /dev/sda
Android获取cpu和内存信息、网址的代码如下:
/ 获取用户硬件信息 /
public static String getMobileInfo() {
//StringBuffer sb = new StringBuffer();
JSONObject mbInfo = new JSONObject();
//通过反射获取用户硬件信息
try {
Field[] fields = BuildclassgetDeclaredFields();
for (Field field : fields) {
// 暴力反射,获取私有信息
fieldsetAccessible(true);
String name = fieldgetName();
String value = fieldget(null)toString();
//sbappend(name + "=" + value);
//sbappend("\n");
mbInfoput(name, value);
}
} catch (Exception e) {
eprintStackTrace();
}
//return sbtoString();
return mbInfotoString();
}
static public String getCpuString(){
if(BuildCPU_ABIequalsIgnoreCase("x86")){
return "Intel";
}
String strInfo = "";
try
{
byte[] bs = new byte[1024];
RandomAccessFile reader = new RandomAccessFile("/proc/cpuinfo", "r");
readerread(bs);
String ret = new String(bs);
int index = retindexOf(0);
if(index != -1) {
strInfo = retsubstring(0, index);
} else {
strInfo = ret;
}
}
catch (IOException ex){
exprintStackTrace();
}
return strInfo;
}
static public String getCpuType(){
String strInfo = getCpuString();
String strType = null;
if (strInfocontains("ARMv5")) {
strType = "armv5";
} else if (strInfocontains("ARMv6")) {
strType = "armv6";
} else if (strInfocontains("ARMv7")) {
strType = "armv7";
} else if (strInfocontains("Intel")){
strType = "x86";
}else{
strType = "unknown";
return strType;
}
if (strInfocontains("neon")) {
strType += "_neon";
}else if (strInfocontains("vfpv3")) {
strType += "_vfpv3";
}else if (strInfocontains(" vfp")) {
strType += "_vfp";
}else{
strType += "_none";
}
return strType;
}
/
@hide
@return
/
public static CPUInfo getCPUInfo() {
String strInfo = null;
try
{
byte[] bs = new byte[1024];
RandomAccessFile reader = new RandomAccessFile("/proc/cpuinfo", "r");
readerread(bs);
String ret = new String(bs);
int index = retindexOf(0);
if(index != -1) {
strInfo = retsubstring(0, index);
} else {
strInfo = ret;
}
}
catch (IOException ex)
{
strInfo = "";
exprintStackTrace();
}
CPUInfo info = parseCPUInfo(strInfo);
infomCPUMaxFreq = getMaxCpuFreq();
return info;
}
private final static String kCpuInfoMaxFreqFilePath = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
private static int getMaxCpuFreq() {
int result = 0;
FileReader fr = null;
BufferedReader br = null;
try {
fr = new FileReader(kCpuInfoMaxFreqFilePath);
br = new BufferedReader(fr);
String text = brreadLine();
if (text != null) {
result = IntegerparseInt(texttrim());
}
} catch (FileNotFoundException e) {
eprintStackTrace();
} catch (IOException e) {
eprintStackTrace();
} finally {
if (fr != null)
try {
frclose();
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
if (br != null)
try {
brclose();
} catch (IOException e) {
// TODO Auto-generated catch block
eprintStackTrace();
}
}
return result;
}
public static class CPUInfo{
public CPUInfo(){
}
public static final int CPU_TYPE_UNKNOWN = 0x00000000;
public static final int CPU_TYPE_ARMV5TE = 0x00000001;
public static final int CPU_TYPE_ARMV6 = 0x00000010;
public static final int CPU_TYPE_ARMV7 = 0x00000100;
public static final int CPU_FEATURE_UNKNOWS = 0x00000000;
public static final int CPU_FEATURE_VFP = 0x00000001;
public static final int CPU_FEATURE_VFPV3 = 0x00000010;
public static final int CPU_FEATURE_NEON = 0x00000100;
public int mCPUType;
public int mCPUCount;
public int mCPUFeature;
public double mBogoMips;
public long mCPUMaxFreq;
}
/
@param cpuInfo
@return
@hide
/
private static CPUInfo parseCPUInfo(String cpuInfo) {
if (cpuInfo == null || ""equals(cpuInfo)) {
return null;
}
CPUInfo ci = new CPUInfo();
cimCPUType = CPUInfoCPU_TYPE_UNKNOWN;
cimCPUFeature = CPUInfoCPU_FEATURE_UNKNOWS;
cimCPUCount = 1;
cimBogoMips = 0;
if (cpuInfocontains("ARMv5")) {
cimCPUType = CPUInfoCPU_TYPE_ARMV5TE;
} else if (cpuInfocontains("ARMv6")) {
cimCPUType = CPUInfoCPU_TYPE_ARMV6;
} else if (cpuInfocontains("ARMv7")) {
cimCPUType = CPUInfoCPU_TYPE_ARMV7;
}
if (cpuInfocontains("neon")) {
cimCPUFeature |= CPUInfoCPU_FEATURE_NEON;
}
if (cpuInfocontains("vfpv3")) {
cimCPUFeature |= CPUInfoCPU_FEATURE_VFPV3;
}
if (cpuInfocontains(" vfp")) {
cimCPUFeature |= CPUInfoCPU_FEATURE_VFP;
}
String[] items = cpuInfosplit("\n");
for (String item : items) {
if (itemcontains("CPU variant")) {
int index = itemindexOf(": ");
if (index >= 0) {
String value = itemsubstring(index + 2);
try {
cimCPUCount = Integerdecode(value);
cimCPUCount = cimCPUCount == 0 1 : cimCPUCount;
} catch (NumberFormatException e) {
cimCPUCount = 1;
}
}
} else if (itemcontains("BogoMIPS")) {
int index = itemindexOf(": ");
if (index >= 0) {
String value = itemsubstring(index + 2);
}
}
}
return ci;
}
/
获取设备内存大小值
@return 内存大小,单位MB
/
public static long getTotalMemory() {
String str1 = "/proc/meminfo";
String str2;
String[] arrayOfString;
long initial_memory = 0;
try {
FileReader localFileReader = new FileReader(str1);
BufferedReader localBufferedReader = new BufferedReader(localFileReader, 8192);
str2 = localBufferedReaderreadLine();
if (str2 != null) {
arrayOfString = str2split("\\s+");
initial_memory = IntegervalueOf(arrayOfString[1])intValue()/1024;
}
localBufferedReaderclose();
return initial_memory;
}
catch (IOException e)
{
return -1;
}
}
/
@hide
@return
/
public CPUInfo getCPUInfo() {
String strInfo = null;
try
{
byte[] bs = new byte[1024];
RandomAccessFile reader = new RandomAccessFile("/proc/cpuinfo", "r");
readerread(bs);
String ret = new String(bs);
int index = retindexOf(0);
if(index != -1) {
strInfo = retsubstring(0, index);
} else {
strInfo = ret;
}
}
catch (IOException ex)
{
strInfo = "";
exprintStackTrace();
}
CPUInfo info = parseCPUInfo(strInfo);
infomCPUMaxFreq = getMaxCpuFreq();
return info;
}
/
获取android CPU类型
@return String CPU类型
/
public static String getCpuModel(){
String cpu_model = "";
CPUInfo in = getCPUInfo();
if ((inmCPUType & CPUInfoCPU_TYPE_ARMV5TE) == CPUInfoCPU_TYPE_ARMV5TE)
cpu_model="armv5";
else if ((inmCPUType & CPUInfoCPU_TYPE_ARMV6) == CPUInfoCPU_TYPE_ARMV6)
cpu_model="armv6";
else if ((inmCPUType & CPUInfoCPU_TYPE_ARMV7) == CPUInfoCPU_TYPE_ARMV7)
cpu_model="armv7";
else
cpu_model="unknown";
return cpu_model;
}
/
获取android CPU特性
@return String CPU特性
/
public static String getCpuFeature(){
String cpu_feature = "";
CPUInfo in = getCPUInfo();
if ((inmCPUFeature & CPUInfoCPU_FEATURE_NEON ) == CPUInfoCPU_FEATURE_NEON)
cpu_feature="neon";
else if ((inmCPUFeature & CPUInfoCPU_FEATURE_VFP ) == CPUInfoCPU_FEATURE_VFP)
cpu_feature="vfp";
else if ((inmCPUFeature & CPUInfoCPU_FEATURE_VFPV3 ) == CPUInfoCPU_FEATURE_VFPV3)
cpu_feature="vfpv3";
else
cpu_feature="unknown";
return cpu_feature;
}
/
获取ip地址
@param mContext Context
@return ip地址字符串
/
public static String getIpAddress(Context mContext) {
String ipAddress = null;
try {
for (Enumeration en = NetworkInterface
getNetworkInterfaces(); enhasMoreElements();) {
NetworkInterface intf = ennextElement();
for (Enumeration enumIpAddr = intf
getInetAddresses(); enumIpAddrhasMoreElements();) {
InetAddress inetAddress = enumIpAddrnextElement();
if (!inetAddressisLoopbackAddress()) {
ipAddress = inetAddressgetHostAddress()toString();
}
}
}
} catch (SocketException ex) {
return null;
}
if (DEBUG) {
Logd(TAG, "ip address:" + ipAddress);
}
return ipAddress;
}
以上就是关于如何在Ubuntu Linux中获取CPU温度全部的内容,包括:如何在Ubuntu Linux中获取CPU温度、C语言 编程实现获取cpu信息、linux windows下怎么获取当前进程的cpu 和内存的消耗的信息 / 蓝讯等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)