实验一 进程调度算法.docx
文本预览下载声明
实验一进程调度算法
一、实验目的1.
1.
1.2.3.4.掌握
1.
2.
3.
4.
掌握Linux2. 6调度算法的原理与实现。 能够根据要求修改Linux2. 6调度算法。 对Linux核心进行编译。
通过实验进一步熟悉操作系统的原理。
二、实验环境
PC 机、VMware Workstation 虚拟机、Red Hat Enterprise Linux 5 操作系 统
三、实验内容
首先了解Linux系统的进程结构和调度原理,然后把Linux2. 6的调度算法 修改成为随机调度算法。最后对修改的调度算法进行编译,并使用新内核替换 老内核。
1>下载本次试验要编译的内核版本:linux-2. 6. 18. tar. bz2;
2、进入root权限把刚下面的内核代码复制到/usr/src/kernels目录下面 去;
代码如下:
查找/usr/src/kernels/linux 2. 6. 18 /kernel/sched. c 文件,右键选择 “文本编辑器”翻开,
在sched. c文件中查找:
PCB * create_process(int id,int priority,int cputime,int alltime,STATE state) (
PCB *p = (PCB *)malloc(sizeof(PCB));p-pid = id;
p-cputime = cputime;p-alltime = alltime;
p-priority = priority;p-state 二 state;
p-next = NULL;p-prev = NULL;
return p;)
void destroy_head(Node *head)(
if(head==NULL)return;free(head);
)void destroy(Node *pnode)
{if(pnode == NULL)return;
Node *p = pnode;p-prev-next=p-next;
p-next-prev=p-prev;cout“进程”p-pid” 已经销毁! n?endl;
free(p);)
void process_running(Node *head)(
if(head == NULL| |head-next == head)return;Node *p = NULL;
while(head-nex t!二head)(
p = head-next;p = pop_front(head);
p-cputime += 1;p-alltimc ==1;
p-priority -= 3;p-state = running;
cout?endl;cout当前正在执行的进程为:“vvp-〉pid?endl;
if(p-priority=0)p-priority =0;
)cout?endl;
coutvv”进程号为 H?p-pid?n n;coutv优先级为 n?p-priority?n n;
cout”剩余 ALLTIME 由 H?p-alltime?H H;cout运彳亍时间 cputime 为 n?p-cputime?n H;
cout?endl;cout?endl;
cout?endl;cout?endl;
if(p-alltime=0)(
p-state = stop;destroy (p);
p = NULL;)
if(p!=NULL)(
p-state = ready;push(head,p);
)show_process(head);
char c = getchar();}
destroy_head(head);)
int main()(
PCB * head=NULL;
init_process(head);PCB *p =NULL;
int PRIORITY = 1;int CPUTIME = 0;
int ALLTIME = 0;STATE state = ready;
int count = 0;int num = 0;
cout”请输入当前运行的进程数,至少5个“endl;cin?num;
for(int i = 0;inum;++i)count+=l;
cout“请输入第count”个进程的优先级和总运行时间 ALLTIMEn?endl;cin?PRIORITY?ALLTIME;
p=create_process(count,PRIORITY,CPUTIME,ALLTIME,state); push(head,p);)
show_process(head);process_running(head);
return 0;)
屏幕截图
c\操作系统实验l\Debug\test.exe请输入当前
显示全部