psched.c~
来自「设有二元函数 f(x,y) = f(x) + f(y) 其中:f(x) = f」· C~ 代码 · 共 41 行
C~
41 行
/* * Filename : psched.c * copyright : (C) 2006 by zhanghonglie : 父进程创建 3 个子进程为它们设置不同的优先数和调 * Function度策略*/#include <stdio.h>#include <stdlib.h>#include <sched.h>#include <sys/time.h>#include <sys/resource.h>int main(int argc, char *argv[]){ int i,j,status; int pid[3]; struct sched_param p[3];for(i=0; i<3;i++){if((pid[i]=fork()) >0){ p[i].sched_priority = (argv[i+1] != NULL) ? atoi(argv[i+1]):10; sched_setscheduler(pid[i],(argv[i+4] != NULL) ? atoi(argv[i+4]) :SCHED_OTHER,&p[i]); setpriority(PRIO_PROCESS,pid[i],(argv[i+1] != NULL) ? atoi(argv[i+1]):10);}else{ sleep(1); for(i=0; i<10; i++){ printf("Child PID = %d priority =%d\n",getpid(),getpriority(PRIO_PROCESS,0)); sleep(1); } exit( EXIT_SUCCESS); } } printf("My child %d policy is %d\n",pid[0],sched_getscheduler(pid[0])); printf("My child %d policy is %d\n",pid[1],sched_getscheduler(pid[1])); printf("My child %d policy is %d\n",pid[2],sched_getscheduler(pid[2])); return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?