进程和cpu绑定
- #include<stdlib.h>
- #include<stdio.h>
- #include<sys/types.h>
- #include<sys/sysinfo.h>
- #include<unistd.h>
- #define __USE_GNU
- #include<sched.h>
- #include<ctype.h>
- #include<string.h>
- int main(int argc, char* argv[])
- {
- int num = sysconf(_SC_NPROCESSORS_CONF);
- int created_thread = 0;
- int myid;
- int i;
- int j = 0;
- cpu_set_t mask;
- cpu_set_t get;
- if (argc != 2)
- {
- printf("usage : ./cpu num/n");
- exit(1);
- }
- myid = atoi(argv[1]);
- printf("system has %i processor(s). /n", num);
- CPU_ZERO(&mask);
- CPU_SET(myid, &mask);
- if (sched_setaffinity(0, sizeof(mask), &mask) == -1)
- {
- printf("warning: could not set CPU affinity, continuing.../n");
- }
- while (1)
- {
- CPU_ZERO(&get);
- if (sched_getaffinity(0, sizeof(get), &get) == -1)
- {
- printf("warning: cound not get cpu affinity, continuing.../n");
- }
- for (i = 0; i < num; i++)
- {
- if (CPU_ISSET(i, &get))
- {
- printf("this process %d is running processor : %d/n",getpid(), i);
- }
- }
- }
- return 0;
- }
进程和cpu绑定的更多相关文章
- Linux进程或线程绑定到CPU
Linux进程或线程绑定到CPU 为了让程序拥有更好的性能,有时候需要将进程或线程绑定到特定的CPU,这样可以减少调度的开销和保护关键进程或线程. 进程绑定到CPU Linux提供一个接口,可以将进程 ...
- linux 将进程或者线程绑定到指定的cpu上
基本概念 cpu亲和性(affinity) CPU的亲和性, 就是进程要在指定的 CPU 上尽量长时间地运行而不被迁移到其他处理器,也称为CPU关联性:再简单的点的描述就将指定的进程或线程绑定到相应的 ...
- CPU绑定操作
使用virsh vcpuinfp命令查看虚拟机VCPU和物理CPU的对应关系 [root@svn ~]# virsh vcpuinfo 16 VCPU: 0 CPU: 3 状态: running CP ...
- 【转】进程与CPU
声明:本博客转自:http://blog.chinaunix.net/uid-20737871-id-1881246.html 简单地说,CPU 亲和性(affinity) 就是进程要在某个给定的 C ...
- 进程和cpu的相关知识和简单调优方案
进程就是一段执行的程序,每当一个程序执行时.对于操作系统本身来说,就创建了一个进程,而且分配了相应的资源.进程能够分为3个类别: 1.交互式进程(I/O) 2.批处理进程 (CPU) ...
- openStack cpu绑定
来自:http://fishcried.com/2015-01-09/cpu_bindings/ 前一篇理解cpu topology对CPU Topology进行了学习总结,这里想总结下OpenSta ...
- OpenStack Nova 高性能虚拟机之 CPU 绑定
目录 文章目录 目录 前文列表 KVM KVM 的功能列表 KVM 工具集 KVM 虚拟机的本质是什么 vCPU 的调度与性能问题 Nova 支持的 vCPU 绑定 vcpu\_pin\_set 配置 ...
- Apache服务器httpd.exe进程占用cpu超过50%的解决方法
httpd.exe进程占用cpu超过50%,关闭掉Apache服务,cpu应用率立刻下降到0. 重新启动Apache又出现占用cpu高的情况. 原因是:httpd.exe和防火墙配置有冲突. 解决 ...
- Linux如何统计进程的CPU利用率
1.0 概述 在Linux的/proc文件系统,可以看到自启动时候开始,所有CPU消耗的时间片:对于个进程,也可以看到进程消耗的时间片.这是一个累计值,可以"非阻塞"的输出.获得一 ...
随机推荐
- Spring学习总结一——SpringIOC容器一
什么是spring spring是一个开源的轻量级的应用开发框架,它提供了IOC和AOP应用,可以减少组件之间的耦合度,即 解耦,spring容器可以创建对象并且管理对象之间的关系. 一:实例化spr ...
- 实例--post请求,完成一个抽奖程序概率的测试
一个web项目测试,测试抽奖概率的正确性,写了一个小代码,验证概率 post和get请求的一个工具类 package kankan_interface; import java.io.IOExcept ...
- 1166 矩阵取数游戏[区间dp+高精度]
1166 矩阵取数游戏 2007年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description [ ...
- C# 文件相关操作
百度搜的,下面这个写的挺全的. FROM Pegasus923 http://www.cnblogs.com/pegasus923/archive/2011/01/26/1944838.html ...
- JDBC学习笔记(一)
public static void main(String[] args) { ResultSet rs = null; Statement stmt = null; Connection conn ...
- Windows命令行中使用SSH连接Linux
转自 http://www.linuxidc.com/Linux/2014-02/96625.htm 1.下载: openssh for Winodws: 免费下载地址在 http://linux.l ...
- js取单选按钮,复选按钮的值
$("input[name=PType]").bind('click', function () { if ($(this).prop("checked")) ...
- HDU4268 Alice and Bob(贪心+multiset)
Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...
- FusionCharts 相关知识
FusionCharts1.平均线: <trendLines><line startValue='{0}' toolText='平均线' color='#FF0000' displa ...
- php curl 的用法 转载
curl 是使用URL语法的传送文件工具,支持FTP.FTPS.HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE和LDAP.curl 支持SSL证书.HTTP POS ...