获取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 ...
随机推荐
- Spark-1.5.2安装--Standalone和Yarn
Spark Standalone 1.下载scala-2.10.6包解压到指定目录,添加环境变量 #SCALA VARIABLES START export SCALA_HOME=/usr/local ...
- C语言学习笔记---好用的函数memcpy与memset
这个主要用于我个人的学习笔记,便于以后查询,顺便分享给大家. 想必在用C的时候难免会与数组,指针,内存这几样东西打交道,先以数组为例,例如有一个数组int a[5] = {1, 2, 3, 4, 5} ...
- System.Drawing.Text.TextRenderingHint 的几种效果
; i < ; i++) { g5.TextRenderingHint = (System.Drawing.Text.TextRenderingHint)i; string txt; ; txt ...
- 如何去掉Myeclipse对JS等文件的验证
或 MyEclipse->validation->Excluded Resource下找到不需要验证的文件或者文件夹 或 右键点击该项目-->MyEclipse-->Exclu ...
- 跟我学算法-tensorflow 实现logistics 回归
tensorflow每个变量封装了一个程序,需要通过sess.run 进行调用 接下来我们使用一下使用mnist数据,这是一个手写图像的数据,训练集是55000*28*28, 测试集10000* 28 ...
- Mysql在spring中jdbc.properties连接配置
############################## mysql的数据源 ############################## jdbc.driver=com.mysql.jdbc.D ...
- c3p0、dbcp和proxool比较
现在常用的开源数据连接池主要有c3p0.dbcp和proxool三种,其中: hibernate开发组推荐使用c3p0; spring开发组推荐使用dbcp(dbcp连接池有weblogic连接池同样 ...
- Spring IOC基础
2.1.1 IOC是什么IOC—Inversion of Control,即“控制反转”,不是什么技术,而是一种设计思想.在Java开发中,IOC意味着将你设计好的对象交给容器控制,而不是传统的在你的 ...
- json和jsonp的区别(转)
原文链接:http://www.cnblogs.com/dowinning/archive/2012/04/19/json-jsonp-jquery.html 前言: 说到AJAX就会不可避免的面临 ...
- glTexGen
[glTexGen] Rather than having to explicitly provide a texture coordinate for each vertex, we can use ...