获取cpu频率的代码
taskset是linux自带的一个命令,可用来将进程绑定到指定CPU
相关的函数有: sched_setaffinity, CPU_CLR, CPU_ISSET, CPU_SET, CPU_ZERO
// cpufreq库可在/usr/lib目录下找到
// 编译: g++ -g -o x x.cpp -lcpufreq
// 需要以root用户执行以下代码
//#include <cpufreq.h>
#include <stdio.h>
#include <sys/sysinfo.h> // get_nprocs
// 如果不存在/usr/include/cpufreq.h
#ifndef _CPUFREQ_H
extern "C" int cpufreq_cpu_exists(unsigned int cpu);
extern "C" unsigned long cpufreq_get_freq_kernel(unsigned int cpu);
extern "C" unsigned long cpufreq_get_freq_hardware(unsigned int cpu);
extern "C" int cpufreq_get_hardware_limits(unsigned int cpu, unsigned long *min, unsigned long *max);
#endif
int main()
{
// 取得cpu core的个数,proc是processor的意思
int nprocs = get_nprocs();
for (int i=0; i<nprocs; ++i)
{
if (0 == cpufreq_cpu_exists(i))
{
unsigned long min_freq = 0;
unsigned long max_freq = 0;
cpufreq_get_hardware_limits(i, &min_freq, &max_freq);
printf("cpu[%d]:\n", i);
printf("min_freq: %lu, max_freq: %lu\n", min_freq, max_freq);
printf("kernel freq: %lu, hardware freq: %lu\n", cpufreq_get_freq_kernel(i), cpufreq_get_freq_hardware(i));
printf("\n");
}
}
return 0;
}
获取cpu频率的代码的更多相关文章
- .net 获取CPU频率 内存 磁盘大小,域名 端口 虚拟目录等
CPU个数: @Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS") CPU类型: @Environment.Get ...
- android 获取 cpu 频率信息
cpu的频率信息可以在/sys/devices/system/cpu/cpu0/cpufreq/路径下读取 比如最高频率路径为:/sys/devices/system/cpu/cpu0/cpufreq ...
- Windows下获取CPU频率
一直想在Windows下取得CPU的时钟速度,找了好久终于找到了函数CallNtPowerInformation,要想使用它,首先必须包含powrprof.h头文件和链接库powerprof.lib. ...
- 获取CPU频率
#include <stdio.h> #include <string.h> float get_cpu_clock_speed() { FILE *fp; char buff ...
- C++ 嵌入汇编 获取CPU信息
#include "windows.h" #include "iostream" #include "string" using names ...
- Android获取cpu和内存信息、网址的代码
android获取手机cpu并判断是单核还是多核 /** * Gets the number of cores available in this device, across all proce ...
- Python获取CPU、内存使用率以及网络使用状态代码
Python获取CPU.内存使用率以及网络使用状态代码_python_脚本之家 http://www.jb51.net/article/134714.htm
- 【VS开发】获取CPU tick tick 周期
多核处理器时,__rdtsc()的使用-编程珠玑第一章 根据书中提供的代码清单1-5,可以完成对于多核处理器的cpu占用率的控制. 但是在使用GetCPUTickCount计时时,下面的算式会出现一点 ...
- C#获取CPU占用率、内存占用、磁盘占用、进程信息
代码: using System; using System.Collections.Generic; using System.Diagnostics; using System.Threading ...
随机推荐
- Centos 文件查找命令
find [搜索范围] [搜索条件] #搜索文件 find / -name install.log #避免大范围搜索,会非常耗费系统资源 #find是在系统当中搜索符合条件的文件名.如果需要匹配,使用 ...
- Angular2 如何使用jquery
网上找了很多版本尝试都不行,最后在stackoverflow上找到一个,尝试完美解决 具体操作步骤如下 1. 安装jquery npm install jquery 2.安装 type for jqu ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(转)
开发工具:VS2015(2012以上)+SQL2008R2以上数据库 您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB 升级后界面效果如下: 日程管理 http://ww ...
- FastDFS:搭建文件管理系统
文章转自:https://www.cnblogs.com/chiangchou/p/fastdfs.html#_label1 一.FastDFS介绍 FastDFS开源地址:https://githu ...
- vue之slot,组件标签嵌套
vue之slot,组件标签嵌套 插槽(Slot),在各种vue的ui插件中,经常见到的多个组件标签相互嵌套(如下)就是以此为基础的. <el-col > <el-checkbox & ...
- openLayers 3 之入门
openLayers 3 之入门 openlayer是web GIS客户端开发提供的javascript类库,也是开源框架,可以加载本地数据进行展示地图 1.下载相关引用的js.css文件 2.类似于 ...
- tornado 自定义session (二)
有了上一步的基础,我们将session改造成一个模块,这样我们就可以通过配置,来使用不同方式(redis,数据库等)的session. 添加一个新目录:TornadoSession conf.py是配 ...
- Spring与Redis的实现
前言 Redis作为缓存还是相当不错的,一定程度上缓解了数据库的IO操作,具体不多说,具体网上查找资料. 实战 不多说,直接上代码. 第一步:所需要的依赖 <!-- redis --> & ...
- MPEG-2码流结构分析
MPEG2视频编码定义在 ISO/IEC13818-2中,MPEG2 video sequence如下图所示 我们可以借助Elecard Stream Analyer工具来分析MPEG2视频码流 MP ...
- (halcon) derivate_vector_field
derivate_vector_field: Convolve a vector field with derivatives of the Gaussian 用高斯导数卷积向量场 derivate_ ...