执行c代码
#include<sched.h> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<errno.h> #include <math.h> int main(int argc,char **argv) { long i,j,temp; char cmd_str[100]; int rc,current_scheduler_policy; unsigned long mask=(unsigned long)atoi(argv[3]); /* processor 0 ->valu=1,and processor 1->value=2 */ struct sched_param my_params;//将要设置的调度参数 printf("The argc value = %d,arv[3]=%d,hope is=1, argv[2]=%d,hope is=90+,argv[1]=%d ",argc,atoi(argv[3]),atoi(argv[2]),atoi(argv[1])); /*if(argc!=4){ printf("usage:RR-FIFO-sched sched_class priority sched_class: 0 for CFS;1 for FIFO;2 for RR "); exit(1); }*/ //增加绑定进程 if (sched_setaffinity(0, sizeof(mask), &mask) <0) { perror("sched_setaffinity"); } my_params.sched_priority = atoi(argv[2]); rc = sched_setscheduler(0,atoi(argv[1]),&my_params); if(rc<0){ perror("sched_setscheduler error "); exit(0); } current_scheduler_policy = sched_getscheduler(0); printf("the PID:%d current scheduler=%d ",getpid(),current_scheduler_policy); for(i=0;i<1024*1024*1024;i++){ for(j=0;j<10;j++) temp++; } //while(1); sprintf(cmd_str,"cat /proc/%d/sched > ./sched-%d; date >> ./sched-%d",getpid(),getpid(),getpid());//sprintf system(cmd_str);//记录各个进程的/proc/PID/sched以及时间信息 return 0; }
通过gcc 链接成可执行文件RR-FIFO2
shell可执行脚本:
#!/usr/bin/bash echo Running a shell #./RR-FIFO-sched 2 90 1& #./RR-FIFO-sched 2 90 1& #taskset -c 0 ./RR-FIFO-sched 2 90& #taskset -c 0 ./RR-FIFO-sched 2 90& #sleep 5s #taskset -c 0 ./RR-FIFO-sched 1 95& #./RR-FIFO-sched 1 95 1& # SCRIP 3 ./RR-FIFO2 2 90 1& # 2 -指定进程为RR类 , 90-priority 1 -绑定到cpu 0 &挂起 ./RR-FIFO2 2 90 1& sleep 5s ./RR-FIFO2 1 95 1&# 2 -指定进程为FIFO类 , 90-priority 1 -绑定到cpu 0 &挂起