高分求解释一道操作系统的实验题,想的我蛋疼啊,求解释
说明:这是我们操作系统的一道实验题,是关于进程调度算法的,以下是老师给出的一道参考程序:
#include <stdio.h>#include <stdlib.h>#include <sched.h>#include <sys/resource.h>#include <sys/time.h>#include <unistd.h>int main(int argc,char *argv[]) { int i; 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; //调试代码 if(argv[i+4] != NULL) { printf("here!---%d\n",atoi(argv[i+4])); } 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); //测试代码 if(argv[i+1] != NULL) { printf("priority is %d\n",atoi(argv[i+1])); } }else { sleep(1); for(i=0;i<10;i++) { printf("CHild PID= %d priotity = %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(0);}