冬Linux的进程根据优先级排队 >根据特定的算法计算出进程的优先级,用一个值表示 >这个值表示把进程如何适当的分配给CPU Linux中进程的优先级是动态的 >调度程序会根据进程的行为周期性的调整进程的优先 级 ●较长时间未分配到CPU的进程,通常个 已经在CPU上运行了较长时间的进程,通常) 嵌入式系统实验室 2023/7/14 Linux操作系统分析 7152 EMBEDDED SYSTEM LABORATORY 5uE料DUAN0 ITUTE FOR AOVANCED5 FUOY OF U百TC
2023/7/14 Linux操作系统分析 7/52 ❖Linux的进程根据优先级排队 ➢根据特定的算法计算出进程的优先级,用一个值表示 ➢这个值表示把进程如何适当的分配给CPU ❖Linux中进程的优先级是动态的 ➢调度程序会根据进程的行为周期性的调整进程的优先 级 ⚫较长时间未分配到CPU的进程,通常↑ ⚫已经在CPU上运行了较长时间的进程,通常↓
与调度相关的系统调用 nice getpriority/setpriority sched getscheduler/sched setscheduler sched getparam/sched setparam sched yield *sched_get priority_min/sched_get priority_max sched rr get interval Ecience and Technolv 嵌入式系统实验室 2023/7/14 Linux操作系统分析 8152 EMBEDDED SYSTEM LABORATORY 5uE料DUAN0 ITUTE FOR AOVANCED5 FUOY OF U百TC
2023/7/14 Linux操作系统分析 8/52 与调度相关的系统调用 ❖nice ❖getpriority/setpriority ❖sched_getscheduler/sched_setscheduler ❖sched_getparam/sched_setparam ❖sched_yield ❖sched_get_priority_min/sched_get_priority_max ❖sched_rr_get_interval
例如 nice(2)-Linux man page Name nice-change process priority Synopsis #include <unistd.h> int nice(int inc); Description 仅作用于调用者进程 nice()adds inc to the nice value for the calling process.(A higher nice value means a low priority.)Only the superuser may specify a negative increment,or priority increase. The range for nice values is described in getpriority(2). Return Value On success,the new nice value is returned (but see NOTES below).On error,-1 is 室 2023/7/1 returned,and errno is set appropriately
2023/7/14 Linux操作系统分析 9/52 例如 仅作用于调用者进程
getpriority(2)-Linux man page Name getpriority,setpriority-get/set program scheduling priority Synopsis #include <sys/time.h> #include <sys/resource.h> int getpriority(int which,int who); int setpriority(int which,int who,int prio); Description The scheduling priority of the process,process group,or user,as indicated by which and who is obtained with the getpriority()call and set with the setpriority()call. The value which is one of PRIO_PROCESS,PRIO_PGRP,or PRIO_USER,and who is interpreted relative to which(a process identifier for PRIO_PROCESS,process group identifier for PRIO_PGRP,and a user ID for PRIO_USER).A zero value for who denotes(respectively)the calling process,the process group of the calling process,or the real user ID of the calling process.Prio is a value in the range-20 to 19(but see the Notes below).The default priority is 0;lower priorities cause more favorable scheduling The getpriority()call returns the highest priority(lowest numerical value)enjoyed by 弋系统实验室 20 any of the specified processes.The setpriority()call sets the priorities of all of the specified processes to the specified value.Only the superuser may lower priorities. SYSTEM LABORATORY TE FOR AOVANCED STUOY DF USTC
2023/7/14 Linux操作系统分析 10/52 又如
sched setscheduler(2)-Linux man page Name sched_setscheduler,sched_getscheduler-set and get scheduling algorithm/parameters Synopsis include <sched.h> int sched setscheduler(pid t pid,int policy, const struct sched param *param) int sched getscheduler(pid t pid); struct sched param int sched priority; }; Description sched_setscheduler()sets both the scheduling policy and the associated parameters for the process identified by pid.If pid equals zero,the scheduler of the calling process will be set.The interpretation of the parameter param depends on the selected policy. Currently,the following three scheduling policies are supported under Linux: SCHED_FIFO,SCHED_RR,SCHED_OTHER,and SCHED_BATCH;their respective semantics are described below. sched_getscheduler()queries the scheduling policy currently applied to the process 2023/7/1 identified by pid.If pid equals zero,the policy of the calling process will be retrieved. 统实验室 MLAB口RATORY UZHDU INSTIYUTE FOR AOVANCED SYUDY DF USTC
2023/7/14 Linux操作系统分析 11/52