1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<sys/types.h>
  4. #include<sys/sysinfo.h>
  5. #include<unistd.h>
  6. #define __USE_GNU
  7. #include<sched.h>
  8. #include<ctype.h>
  9. #include<string.h>
  10. int main(int argc, char* argv[])
  11. {
  12. int num = sysconf(_SC_NPROCESSORS_CONF);
  13. int created_thread = 0;
  14. int myid;
  15. int i;
  16. int j = 0;
  17. cpu_set_t mask;
  18. cpu_set_t get;
  19. if (argc != 2)
  20. {
  21. printf("usage : ./cpu num/n");
  22. exit(1);
  23. }
  24. myid = atoi(argv[1]);
  25. printf("system has %i processor(s). /n", num);
  26. CPU_ZERO(&mask);
  27. CPU_SET(myid, &mask);
  28. if (sched_setaffinity(0, sizeof(mask), &mask) == -1)
  29. {
  30. printf("warning: could not set CPU affinity, continuing.../n");
  31. }
  32. while (1)
  33. {
  34. CPU_ZERO(&get);
  35. if (sched_getaffinity(0, sizeof(get), &get) == -1)
  36. {
  37. printf("warning: cound not get cpu affinity, continuing.../n");
  38. }
  39. for (i = 0; i < num; i++)
  40. {
  41. if (CPU_ISSET(i, &get))
  42. {
  43. printf("this process %d is running processor : %d/n",getpid(), i);
  44. }
  45. }
  46. }
  47. return 0;
  48. }

进程和cpu绑定的更多相关文章

  1. Linux进程或线程绑定到CPU

    Linux进程或线程绑定到CPU 为了让程序拥有更好的性能,有时候需要将进程或线程绑定到特定的CPU,这样可以减少调度的开销和保护关键进程或线程. 进程绑定到CPU Linux提供一个接口,可以将进程 ...

  2. linux 将进程或者线程绑定到指定的cpu上

    基本概念 cpu亲和性(affinity) CPU的亲和性, 就是进程要在指定的 CPU 上尽量长时间地运行而不被迁移到其他处理器,也称为CPU关联性:再简单的点的描述就将指定的进程或线程绑定到相应的 ...

  3. CPU绑定操作

    使用virsh vcpuinfp命令查看虚拟机VCPU和物理CPU的对应关系 [root@svn ~]# virsh vcpuinfo 16 VCPU: 0 CPU: 3 状态: running CP ...

  4. 【转】进程与CPU

    声明:本博客转自:http://blog.chinaunix.net/uid-20737871-id-1881246.html 简单地说,CPU 亲和性(affinity) 就是进程要在某个给定的 C ...

  5. 进程和cpu的相关知识和简单调优方案

    进程就是一段执行的程序,每当一个程序执行时.对于操作系统本身来说,就创建了一个进程,而且分配了相应的资源.进程能够分为3个类别:     1.交互式进程(I/O)     2.批处理进程 (CPU) ...

  6. openStack cpu绑定

    来自:http://fishcried.com/2015-01-09/cpu_bindings/ 前一篇理解cpu topology对CPU Topology进行了学习总结,这里想总结下OpenSta ...

  7. OpenStack Nova 高性能虚拟机之 CPU 绑定

    目录 文章目录 目录 前文列表 KVM KVM 的功能列表 KVM 工具集 KVM 虚拟机的本质是什么 vCPU 的调度与性能问题 Nova 支持的 vCPU 绑定 vcpu\_pin\_set 配置 ...

  8. Apache服务器httpd.exe进程占用cpu超过50%的解决方法

    httpd.exe进程占用cpu超过50%,关闭掉Apache服务,cpu应用率立刻下降到0.  重新启动Apache又出现占用cpu高的情况.  原因是:httpd.exe和防火墙配置有冲突. 解决 ...

  9. Linux如何统计进程的CPU利用率

    1.0 概述 在Linux的/proc文件系统,可以看到自启动时候开始,所有CPU消耗的时间片:对于个进程,也可以看到进程消耗的时间片.这是一个累计值,可以"非阻塞"的输出.获得一 ...

随机推荐

  1. Spring学习总结一——SpringIOC容器一

    什么是spring spring是一个开源的轻量级的应用开发框架,它提供了IOC和AOP应用,可以减少组件之间的耦合度,即 解耦,spring容器可以创建对象并且管理对象之间的关系. 一:实例化spr ...

  2. 实例--post请求,完成一个抽奖程序概率的测试

    一个web项目测试,测试抽奖概率的正确性,写了一个小代码,验证概率 post和get请求的一个工具类 package kankan_interface; import java.io.IOExcept ...

  3. 1166 矩阵取数游戏[区间dp+高精度]

    1166 矩阵取数游戏 2007年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description [ ...

  4. C# 文件相关操作

    百度搜的,下面这个写的挺全的.   FROM Pegasus923 http://www.cnblogs.com/pegasus923/archive/2011/01/26/1944838.html ...

  5. JDBC学习笔记(一)

    public static void main(String[] args) { ResultSet rs = null; Statement stmt = null; Connection conn ...

  6. Windows命令行中使用SSH连接Linux

    转自 http://www.linuxidc.com/Linux/2014-02/96625.htm 1.下载: openssh for Winodws: 免费下载地址在 http://linux.l ...

  7. js取单选按钮,复选按钮的值

    $("input[name=PType]").bind('click', function () { if ($(this).prop("checked")) ...

  8. HDU4268 Alice and Bob(贪心+multiset)

    Problem Description Alice and Bob's game never ends. Today, they introduce a new game. In this game, ...

  9. FusionCharts 相关知识

    FusionCharts1.平均线: <trendLines><line startValue='{0}' toolText='平均线' color='#FF0000' displa ...

  10. php curl 的用法 转载

    curl 是使用URL语法的传送文件工具,支持FTP.FTPS.HTTP HTPPS SCP SFTP TFTP TELNET DICT FILE和LDAP.curl 支持SSL证书.HTTP POS ...