太原理工大学操作系统实验报告2016

内容发布更新时间 : 2024/11/8 22:43:20星期一 下面是文章的全部内容请认真阅读。

位置)。每过一个时间片,运行进程占用处理机的时间片数加1,然后比较占用处理机的时间片数是否与该进程的轮转时间片数相等,若相等说明已到达轮转时间,应将现运行进程排到就绪链末尾,调度链首进程占用处理机,且改变它们的进程状态,直至所有进程完成各自的时间片。

三、实验代码:

#include #include #define furthest 5

struct process /*PCB STRUCTURE*/ {

int id; int priority; int cputime; int alltime; char state; int next;

}prochain[furthest - 1]; int procnum; int rand(); int algo;

int run, head, tail, j; void print(); void insert(int q); void insert2(); void timesch(); void init(); void prisch();

int main() /*MAIN PROGRAM*/ {

agan: printf(\);

scanf(\, &algo); if (algo == 2) {

printf(\);

}

}

init(); prisch();

else { }

for (j = 1; j <= 40; j++) { }

printf(\);

for (j = 1; j <= 40; j++) { }

printf(\);

printf(\); getchar();

printf(\); printf(\); if (algo == 1) { } else { }

printf(\); goto agan;

printf(\); init(); timesch();

void print() /*PRINT THE RUNNING PROCESS,WAITING {

int k, p;

QUEUE AND PCB SEQUENCE LIST*/

for (k = 1; k <= 40; k++)

printf(\);

printf(\); printf(\);

printf(\, prochain[run].id); p = head; while (p != 0) { }

printf(\);

for (k = 1; k <= 40; k++)

printf(\); printf(\, p); p = prochain[p].next;

printf(\);

printf(\); for (k = 1; k

printf(\, prochain[k].id);

printf(\);

printf(\); for (k = 1; k

printf(\, prochain[k].priority);

printf(\);

printf(\); for (k = 1; k

printf(\, prochain[k].cputime);

printf(\);

printf(\); for (k = 1; k

printf(\, prochain[k].alltime);

printf(\);

printf(\); for (k = 1; k

printf(\, prochain[k].state);

}

printf(\);

printf(\); for (k = 1; k

printf(\, prochain[k].next);

printf(\);

void insert(int q) /*INSERT A PROCESS*/ { }

void insert2() /*PUT A PROCESS ONTO THE TAIL OF THE QUEUE*/ { prochain[tail].next = run; }

void init() /*CREATE A WAITING QUEUE*/ {

int i; head = 0; if (algo == 2) {

for (i = 1; i

prochain[run].next = 0; int p, s; p = head;

s = prochain[head].next;

while ((prochain[q].priority

prochain[p].next = q; prochain[q].next = s;

p = s;

s = prochain[s].next;

prochain[i].id = i;

prochain[i].priority = (rand() + 11) % 41;

prochain[i].cputime = 0;

prochain[i].alltime = (rand() + 1) % 7; prochain[i].state = 'W'; prochain[i].next = 0;

if ((prochain[i].priority

run = head;

prochain[run].state = 'R';

for (i = 1; i

prochain[furthest].next = 0;

prochain[i].id = i;

prochain[i].priority = (rand() + 1) % 3 + 1; prochain[i].cputime = 0;

prochain[i].alltime = (rand() + 1) % 7; prochain[i].state = 'W';

prochain[i].next = (i + 1) % (furthest + 1); }

insert(prochain[i].id);

else { }

prochain[i].next = head; head = prochain[i].id;

head = prochain[head].next;

prochain[run].next = 0;

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4 ceshi