成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

c語言中是什么調(diào)度函數(shù) c語言調(diào)試函數(shù)

處理機調(diào)度算法的實現(xiàn) 用C語言

網(wǎng)絡(luò)答案,經(jīng)過驗證:

成都創(chuàng)新互聯(lián)是工信部頒發(fā)資質(zhì)IDC服務(wù)器商,為用戶提供優(yōu)質(zhì)的鄭州服務(wù)器托管服務(wù)

#include "stdio.h"

#include stdlib.h

#include conio.h

#define getpch(type) (type*)malloc(sizeof(type))

#define NULL 0

struct pcb { /* 定義進程控制塊PCB */

char name[10];

char state;

int super;

int ntime;

int rtime;

struct pcb* link;

}*ready=NULL,*p;

typedef struct pcb PCB;

void sort() /* 建立對進程進行優(yōu)先級排列函數(shù)*/

{

PCB *first, *second;

int insert=0;

if((ready==NULL)||((p-super)(ready-super))) /*優(yōu)先級最大者,插入隊首*/

{

p-link=ready;

ready=p;

}

else /* 進程比較優(yōu)先級,插入適當?shù)奈恢弥?/

{

first=ready;

second=first-link;

while(second!=NULL)

{

if((p-super)(second-super)) /*若插入進程比當前進程優(yōu)先數(shù)大,*/

{ /*插入到當前進程前面*/

p-link=second;

first-link=p;

second=NULL;

insert=1;

}

else /* 插入進程優(yōu)先數(shù)最低,則插入到隊尾*/

{

first=first-link;

second=second-link;

}

}

if(insert==0) first-link=p;

}

}

void input() /* 建立進程控制塊函數(shù)*/

{

int i,num;

system("cls"); /*清屏*/

printf("\n 請輸入進程數(shù): ");

scanf("%d",num);

for(i=1;i=num;i++)

{

printf("\n 進程號No.%d:\n",i);

p=getpch(PCB);

printf("\n 輸入進程名:");

scanf("%s",p-name);

printf("\n 輸入進程優(yōu)先數(shù):");

scanf("%d",p-super);

printf("\n 輸入進程運行時間:");

scanf("%d",p-ntime);

printf("\n");

p-rtime=0;p-state='W';

p-link=NULL;

sort(); /* 調(diào)用sort函數(shù)*/

}

}

int space()

{

int l=0;

PCB* pr=ready;

while(pr!=NULL)

{

l++;

pr=pr-link;

}

return(l);

}

void disp(PCB * pr) /*建立進程顯示函數(shù),用于顯示當前進程*/

{

printf("\n 進程名\t 狀態(tài)\t 優(yōu)先數(shù)\t 需要運行時間\t 已經(jīng)運行時間\n");

printf("|%s\t",pr-name);

printf("|%c\t",pr-state);

printf("|%d\t",pr-super);

printf("|%d\t\t",pr-ntime);

printf("|%d\t",pr-rtime);

printf("\n");

}

void check() /* 建立進程查看函數(shù) */

{

PCB* pr;

printf("\n **** 當前正在運行的進程是:\n"); /*顯示當前運行進程*/

disp(p);

pr=ready;

printf("\n **** 當前就緒隊列狀態(tài)為:\n"); /*顯示就緒隊列狀態(tài)*/

while(pr!=NULL)

{

disp(pr);

pr=pr-link;

}

}

void destroy() /*建立進程撤消函數(shù)(進程運行結(jié)束,撤消進程)*/

{

printf("\n 進程 [%s] 已完成.\n",p-name);

free(p);

}

void running() /* 建立進程就緒函數(shù)(進程運行時間到,置就緒狀態(tài)*/

{

(p-rtime)++;

if(p-rtime==p-ntime)

destroy(); /* 調(diào)用destroy函數(shù)*/

else

{

(p-super)--;

p-state='W';

sort(); /*調(diào)用sort函數(shù)*/

}

}

void main() /*主函數(shù)*/

{

int len,h=0;

char ch;

input();

len=space();

while((len!=0)(ready!=NULL))

{

ch=getchar()();

h++;

printf("-----------------------------------------------------");

printf("\n 現(xiàn)在是第%d次運行: \n",h);

p=ready;

ready=p-link;

p-link=NULL;

p-state='R';

check();

running();

printf("\n 按任意鍵繼續(xù)......\n");

}

printf("\n\n 進程已經(jīng)完成.\n");

}

c語言中什么是調(diào)用函數(shù)和被調(diào)用函數(shù)

調(diào)用函數(shù)就是計算機編譯或運行時,使用某個函數(shù)來完成相關(guān)命令。對無參函數(shù)調(diào)用時則無實際參數(shù)表。實際參數(shù)表中的參數(shù)可以是常數(shù)、變量或其它構(gòu)造類型數(shù)據(jù)及表達式。各實參之間用逗號分隔。

這兩個定義是相對的,比如說你自己定義編寫了一個函數(shù),然后在后面的編寫語句中要用到你之前編寫的函數(shù),你引用了,那個函數(shù)就是被調(diào)用函數(shù),你正在寫的那個主函數(shù)就是調(diào)用函數(shù)。

C語言模擬操作系統(tǒng)進程調(diào)度和管理

給,已經(jīng)編譯運行通過了,簡單寫的:

#includestdio.h

#includetime.h

#includestdlib.h

/*********************以下是全局數(shù)據(jù)結(jié)構(gòu)和變量***********************/

/*PCB 結(jié)構(gòu)*/

struct PCB{

int pname;

int pri;

int runtime;

int waittime;

struct PCB *next;

}pcb[7];

/* 運行指針*/

struct PCB *running;

/*高優(yōu)先級就緒隊列頭指針*/

struct PCB *Hready;

/*低優(yōu)先級隊列頭指針*/

struct PCB *Lready;

/*等待隊列頭指針*/

struct PCB *wait;

int sig=0;

/**************************以下是函數(shù)說明****************************/

/*利用循環(huán)實現(xiàn)延遲*/

void delay();

/*模擬進程3-9*/

void proc(struct PCB *running);

/*將node插入到head所指示的隊列的尾部*/

void InsertIntoQueueTail(struct PCB ** head,struct PCB *node);

/*進程調(diào)度函數(shù)*/

int proc_switch();

/*進程等待函數(shù)*/

void proc_wait();

/*進程喚醒函數(shù)*/

int proc_wakeup();

/************************以下是函數(shù)定義及注釋************************/

/*主函數(shù)*/

main()

{

int i;

/*初始化,創(chuàng)建進程3-9,置低優(yōu)先級,等待時間為0,

依次插入低優(yōu)先級隊列*/

for(i = 0;i 7;i++){

pcb[i].pname = i+3;

pcb[i].pri = 0;

pcb[i].waittime = 0;

InsertIntoQueueTail(Lready,pcb[i]);

}

/*等待隊列和高優(yōu)先級隊列為空*/

wait = NULL;

Hready=NULL;

printf("\nThe process_switch begin:\n");

/*模擬進程調(diào)度開始*/

for(;;)

{

switch(sig){

case 0:/*無進程等待調(diào)度,打印信息并返回*/

if(!proc_switch())

{

printf("No Process to run,press any key to return:\n");

getchar();

}

break;

case 1:proc_wait();

break;

case 3:

case 4:

case 5:

case 6:

case 7:

case 8:

case 9:proc(running);

break;

default:printf("\nerror!");

exit(-1);

}

}

}

/*功能:延遲一個時間片*/

/*入口參數(shù):無*/

/*出口參數(shù):無*/

void delay()

{

int i,j;

for(i=0;i20000;i++)

for(j=0;j10000;j++)

{

}

}

/*功能:進程3-9*/

/*入口參數(shù):運行指針*/

/*出口參數(shù):無*/

void proc(struct PCB * running)

{

int i;

srand( (unsigned)time( NULL ) );

/*顯示當前運行的進程的id*/

printf("\nNow Process %d is running\n",running-pname);

/*當前進程執(zhí)行running-runtime個時間片*/

for(i=running-runtime;i0;i--){

/*顯示剩余的時間片*/

printf("%d time slice(s) left\n",i);

/*延遲*/

delay();

proc_wakeup();

/*產(chǎn)生一個1到1000的隨機數(shù),若該隨機數(shù)小余100,當前進程等待,*/

if((rand()%1000+1)100){

printf("Process %d begins to wait.\n",running-pname);

sig=1;

return;

}

}

/*顯示時間片耗盡,進程轉(zhuǎn)為低優(yōu)先級就緒狀態(tài)*/

printf("Time slices for process %d exhausted.\n",running-pname);

InsertIntoQueueTail(Hready,running);

sig=0;

return;

}

/*功能:將一個節(jié)點插入隊列尾部*/

/*入口參數(shù):隊列頭指針地址head,待插入結(jié)點node*/

/*出口參數(shù):無*/

void InsertIntoQueueTail(struct PCB **head,struct PCB *node)

{

struct PCB *p;

node-next=NULL;

/*被插入隊列為空*/

if(*head==NULL){

*head=node;

return;

}

/*被插入隊列不為空*/

else{

p=*head;

/*找到隊列的最后一個結(jié)點*/

while(p-next!=NULL) p=p-next;

p-next=node;

}

}

/*功能:進程調(diào)度*/

/*入口參數(shù):無*/

/*出口參數(shù):若調(diào)度成功,返回1,否則返回0*/

int proc_switch()

{

/*若高優(yōu)先級就緒隊列和低優(yōu)先級就緒隊列均為空,則循環(huán)執(zhí)行進程喚醒*/

while(Hready == NULL Lready == NULL)

if(!proc_wakeup()) return 0;

/*若高優(yōu)先級就緒隊列非空,則執(zhí)行其第一個進程,分配2個時間片*/

if(Hready != NULL){

running = Hready;

Hready = Hready - next;

running-runtime = 2;

}

/*若高優(yōu)先級就緒隊列為空,則執(zhí)行低優(yōu)先級就緒隊列的第一個進程,

分配5個時間片*/

else{

running = Lready;

Lready=Lready - next;

running - runtime = 5;

}

/*別調(diào)度進程的id賦給sig*/

sig = running - pname;

return 1;

}

/*功能:進程等待。將當前運行進程置高優(yōu)先級,等待時間為20,

插入等待隊列尾部*/

/*入口參數(shù):無*/

/*出口參數(shù):無*/

void proc_wait()

{

struct PCB *p;

running-pri=1;

running-waittime=20;

InsertIntoQueueTail(wait,running);

sig=0;

return;

}

/*功能:進程喚醒*/

/*入口參數(shù):無*/

/*出口參數(shù):若等待隊列為空,則返回0,否則返回1*/

int proc_wakeup()

{

struct PCB *p,*last,*MoveToReady;

p = wait;

/*等待隊列為空,返回0*/

if(p == NULL) return 0;

/*延遲*/

delay();

/*等待隊列中每個進程的等待時間減1*/

while(p != NULL){

p - waittime -= 1;

p=p-next;

}

p=wait;

/*從等待隊列中摘除等待時間為0的進程,插入到高優(yōu)先級就緒隊列的尾部*/

while(p!=NULL){

if(p - waittime == 0){

MoveToReady = p;

if (p == wait)

wait = p-next;

else

last - next = p-next;

p = p - next;

InsertIntoQueueTail(Hready,MoveToReady);

}

else{

p = p - next;

}

}

sig =0;

return 1;

}

分享題目:c語言中是什么調(diào)度函數(shù) c語言調(diào)試函數(shù)
文章鏈接:http://jinyejixie.com/article18/dopcegp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、Google、標簽優(yōu)化響應(yīng)式網(wǎng)站、手機網(wǎng)站建設(shè)面包屑導航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護公司