设为首页 加入收藏

TOP

SMP系统Linux下的进程绑定指定CPU
2014-11-24 12:42:41 来源: 作者: 【 】 浏览:0
Tags:SMP 系统 Linux 进程 绑定 指定 CPU

小注:SMP系统Linux下的进程绑定指定CPU


#include
#include
#include
#include
#include


#define __USE_GNU
#include
#include
#include


int main(int argc, char* argv[])
{
int num = sysconf(_SC_NPROCESSORS_CONF);
pid_t pid;
int status;
int myid;
cpu_set_t mask;
//cpu_set_t get;
char * strv[ ]={"insmod","/root/linux-bcm-core.ko","init=all",(char *)0};
char * strp[ ]={"PATH=/sbin",0};


if (argc != 2)
{
printf("usage : ./cpu num\n");
exit(1);
}


pid = fork();
if(pid < 0)
{
perror("Process creation failed\n");
exit(1);
}
else if(0 == pid)
{
printf("child process is running\n");
printf("My pid = %d ,parentpid = %d\n",getpid(),getppid());

myid = atoi(argv[1]);
printf("system has %i processor(s). \n", num);
CPU_ZERO(&mask);
CPU_SET(myid, &mask);
if (sched_setaffinity(getpid(), sizeof(mask), &mask) == -1)
{
printf("warning: could not set CPU affinity, continuing...\n");
}


//execl("/sbin/insmod","insmod","/root/linux-bcm-core.ko","init=all",(char * )0);
//system("/sbin/insmod /root/linux-bcm-core.ko init=all");
execve("/sbin/insmod",strv,strp);
exit(0);
}
else
{
printf("Parent process is runnig\n");
}
wait(&status);
exit(0);
}



关键名词CPU亲合力


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇U-Boot增加对JFFS2分区的识别与加.. 下一篇Linux 下MD5的C语言实现

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)
·SQL CREATE INDEX 语 (2025-12-25 01:21:45)
·Shell 传递参数 (2025-12-25 00:50:45)
·Linux echo 命令 - (2025-12-25 00:50:43)