
正文
轮转法调度java代码 轮转调度q=1
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
用JAVA实现时间片轮转调度算法
你先用C++写,然后做成DLL。
再用java去调就好了。
一般java做底层控制和调用都会这么做。
就像io什么的,都是去调用C的代码完成的
一般java调用c写的dll代码都比较方便。
c调用java的代码几乎不可能。
相关问答
Q1: 进程调度算法模拟程序设计
public class PrivilegeProcess {
public static void main(String[] args) {
MyQueue myqueue = new MyQueue();//声明队列
PCB[] pcb = {new PCB(001,8,1),new PCB(002,7,9),new PCB(003,3,8),new PCB(004,1,7),new PCB(005,7,4)};
PCB para = new PCB();
for(int i=0;ipcb.length;i++){//初始化后首先执行一次排序,这里使用的是选择排序,优先级高的先入队
for(int j=i;jpcb.length;j++){
if(pcb[i].privilege pcb[j].privilege){
para = pcb[i];
pcb[i] = pcb[j];
pcb[j] = para;
}
}
}
System.out.println("初次入队后各进程的顺序:");
for(int i=0;ipcb.length;i++){
System.out.println("初次入队后 # processname : " + pcb[i].name + " totaltime : " + pcb[i].totaltime + " privilege :" + pcb[i].privilege);
}
System.out.println();
myqueue.start(pcb);
}
}
class MyQueue {
int index = 0;
PCB[] pc = new PCB[5];
PCB[] pc1 = new PCB[4];
PCB temp = new PCB();
public void enQueue(PCB process){//入队算法
if(index==5){
System.out.println("out of bounds !");
return;
}
pc[index] = process;
index++;
}
public PCB deQueue(){//出队算法
if(index==0)
return null;
for(int i=0;ipc1.length;i++){
pc1[i] = pc[i+1];
}
index--;
temp = pc[0];
for(int i=0;ipc1.length;i++){
pc[i] = pc1[i];
}
return temp;
}
public void start(PCB[] pc){//显示进程表算法
while(pc[0].isNotFinish==true||pc[1].isNotFinish==true||pc[2].isNotFinish==true||pc[3].isNotFinish==true||pc[4].isNotFinish==true){
//*注意:||运算符,所有表达式都为false结果才为false,否则为true
for(int i=0;ipc.length;i++){
pc[i].run(this);
}
System.out.println();
for(int i=0;ipc.length;i++){//所有进程每执行完一次时间片长度的运行就重新按优先级排列一次
for(int j=i;jpc.length;j++){
if(pc[i].privilege pc[j].privilege){
temp = pc[i];
pc[i] = pc[j];
pc[j] = temp;
}
}
}
}
}
}
class PCB {//声明进程类
int name,totaltime,runtime,privilege;
boolean isNotFinish;
public PCB(){
}
public PCB(int name, int totaltime, int privilege){
this.name = name;//进程名
this.totaltime = totaltime;//总时间
this.privilege = privilege;//优先级别
this.runtime = 2;//时间片,这里设值为2
this.isNotFinish = true;//是否执行完毕
System.out.println("初始值: processname : " + name + " totaltime : " + totaltime + " privilege :" + privilege );
System.out.println();
}
public void run (MyQueue mq){//进程的基于时间片的执行算法
if(totaltime1){
totaltime-=runtime;//在总时间大于1的时候,总时间=总时间-时间片
privilege--;
System.out.println(" processname : " + name + " remaintime : " + totaltime + " privilege :" + privilege );
}else if(totaltime==1){
totaltime--;//在总时间为1时,执行时间为1
privilege--;
System.out.println(" processname : " + name + " remaintime : " + totaltime + " privilege :" + privilege );
}else{
isNotFinish = false;//总时间为0,将isNotFinish标记置为false
}
if(isNotFinish==true){
mq.deQueue();
mq.enQueue(this);
}
}
}
Q2: 基于优先数的时间片轮转调度算法调度处理器
没有完全符合的,但是差不多的,你自己改改吧!
#includeiostream.h
#includestdlib.h
#includestring.h
typedef struct PCBA
{
char name[30];
int round;
int prio;
int cputime;
int needtime;
char state;
struct PCBA *next;
} PCB,*CurrentRunPCB,*LinkQueue;
CurrentRunPCB SelMosHeiPrio(LinkQueue *Q);//从Q链表中选择一个优先级最大的进程
void InitQueue(LinkQueue *Q);//初始化链表Q,如果链表没有头指针,可以省略;
void InsertQueue(LinkQueue * Q,PCB* run);
{
}//将Run结点插入链表Q中,表示就绪队列里多了一个进程
void Priosch(LinkQueue Wait_Queue,LinkQueue Finish_Queue)//优先法运行,从就绪队列Wait_Queue中选择进程执行,(选择队列中优先级最高的进程),执行结束的进程放入完成队列中;
{ while (WaitQueue!=NULL)
{
CurrentRunPCB run=SelMosHeiPrio(WaitQueue); //run为就绪队列中优先级最高的进程
run-cputime+=2;//时间片为2
run-needtime-=2;
run-prio=50-run-needtime;//动态优先级,但是优先级随着运行时间的增加,优先级增加,所以谁优先级高会一直占用CPU
run-state='r';
if(run-needtime0)
{ run-state='w';
InsertQueue(WaitQueue,run) ;
}
else
{cout"当前运行进称为:"run-name"运行结束后就绪队列情况:"'\n';
run-state='F';
run-needtime=0;
InsertQueue(FinishQueue,run) ;
Print(WaitQueue);
}
//当然可以采用不看进程运行过程,直接将优先级高的运行完,插入完成队列
/*
CurrentRunPCB run=SelMosHeiPrio(WaitQueue);
cout"当前运行进称为:"run-name"运行结束后就绪队列情况:"'\n';
Print(WaitQueue);
run-cputime=run-needtime;
run-needtime=0;
run-prio=50;//动态优先级,但是优先级随着运行时间的增加,优先级增加,所以谁优先级高会一直占用CPU
run-state='F';
InsertQueue(FinishQueue,run) ;*/
}
void Print(LinkQueue*Q)//将队列的元素显示输出,输出包含进程名,进程CPUTIME,NEEDTIME,状态,优先级
{LinkQueue p=*Q;
cout"name cputime needtime state prio'"'\n';
while (p!=NULL)
{ coutp-name'\t'p-cputime'\t'p-needtime'\t'p-state'\t'p-prio'\n';
p=p-next;
}
}
CurrentRunPCB DeQueue(LinkQueue*Q)//从就绪队列中取出一个进程
{LinkQueue p=*Q;
*Q=(*Q)-next;
p-next=NULL;
return p;
}
void Roundsch(LinkQueue WaitQueue,LinkQueue FinishQueue)//轮转法运行,从就绪队列Wait_Queue中选择进程执行一个时间片,执行结束的进程放入完成队列中;若一个时间片未能执行完的进程再插入到就绪队列
{ while (WaitQueue!=NULL)
{
CurrentRunPCB run=DeQueue(WaitQueue);
cout"当前运行进称为:"run-name"运行结束后就绪队列情况:"'\n';
run-cputime+=2;//时间片为2
run-needtime-=2;
run-prio=50- run-cputime;
run-state='r';
if(run-needtime0)
{InsertQueue(WaitQueue,run) ;
run-state='w';
}
else
{run-state='F';
run-needtime=0;
InsertQueue(FinishQueue,run) ;
}
Print(WaitQueue);
}
cout"完成队列情况:"'\n';
Print(FinishQueue);
}
void SetAllpro(LinkQueue*Q)//设置优先级函数50-p-needtime
{int max=0;
LinkQueue p,t;
t=NULL;
p=*Q;
if (p!=NULL)
{
max=p-prio;
p=p-next;
while(p)
{
if (maxp-prio) max=p-prio;
p=p-next;
}
p=*Q;
t=*Q;
if (t==pmax==t-prio)
{*Q=(*Q)-next;
t-next=NULL;
return t;}
else{
t=t-next;
while(t)
{
if (max==t-prio)
{
p-next=t-next;
t-next=NULL;
return t;
}
else{p=t;
t=t-next;
}
}
}
}
return t;
}
void main()
{
PCBA *pcb0,*pcb1,*pcb2,*pcb3,*pcb4; //five processes 五个进程
LinkQueue Wait_Queue,Finish_Queue; //两个队列 等待和完成
Wait_Queue=NULL; //给队列赋初值,如果带有头指针的链表,可以用函数;
Finish_Queue=NULL;
//InitQueue(Wait_Queue);
//InitQueue(Finish_Queue);
char ch;
//给各个进程设置初值
pcb0= new PCBA();
pcb1= new PCBA();
pcb2= new PCBA();
pcb3= new PCBA();
pcb4= new PCBA();
//example
strcpy(pcb0-name,"process1");
pcb0-round=2;
pcb0-prio=0;
pcb0-cputime=0;
pcb0-needtime=5;
pcb0-state='W';
pcb0-next=NULL;
strcpy(pcb1-name,"process2");
pcb1-round=2;
pcb1-prio=0;
pcb1-cputime=0;
pcb1-needtime=7;
pcb1-state='W';
pcb1-next=NULL;
strcpy(pcb2-name,"process3");
pcb2-round=2;
pcb2-prio=0;
pcb2-cputime=0;
pcb2-needtime=3;
pcb2-state='W';
pcb2-next=NULL;
strcpy(pcb3-name,"process4");
pcb3-round=2;
pcb3-prio=0;
pcb3-cputime=0;
pcb3-needtime=11;
pcb3-state='W';
pcb3-next=NULL;
strcpy(pcb4-name,"process5");
pcb4-round=2;
pcb4-prio=0;
pcb4-cputime=0;
pcb4-needtime=8;
pcb4-state='W';
pcb4-next=NULL;
//将各个进程插入就绪队列中
InsertQueue(Wait_Queue,pcb0);
InsertQueue(Wait_Queue,pcb1);
InsertQueue(Wait_Queue,pcb2);
InsertQueue(Wait_Queue,pcb3);
InsertQueue(Wait_Queue,pcb4);
//利用此算法实现Wait_Queue中prio=50-needtime;
SetAllpro(Wait_Queue);
cout"请输入选择的调度算法(1 or 2 or anykey exit!):"endl;
cinch;
switch(ch)
{
case '1':
Print(Wait_Queue);
Roundsch(Wait_Queue,Finish_Queue);
break;
case '2':
Print(Wait_Queue);
Priosch(Wait_Queue,Finish_Queue);
break;
default :
cout"你选择了退出!"endl;
system("pause");
return;
}
return;
}
Q3: 优先级调度算法如何用JAVA实现
没java的 发段源代码给你 有兴趣自己慢慢理解
#include time.h
#include dos.h
#include math.h
#include conio.h
#include stdio.h
#include stdlib.h
#include time.h
#include graphics.h
#define ESC 0x1b
#define ENTER 0x0d
#define TRUE 1
#define FALSE 0
/*每隔TIME秒就变换一次优先级*/
#define TIME 5
/*数据结构*/
/****************************************************************/
enum _Status/*进程状态枚举*/
{
READY =0,/*就绪*/
RUN,/*执行中*/
SUSPEND,/*挂起*/
};
typedef enum _Status Status;
/****************************************************************/
struct _Pcb/*进程结构*/
{
int PID;/*进程ID,ID为负数的进程为系统后备队列的作业*/
int Time;/*进程运行需要的时间*/
int Prior;/*进程的优先级,越大越优先*/
Status Sts;/*状态*/
struct _Pcb *Next;/*指向本进程队列中下个进程的PCB*/
};
typedef struct _Pcb PCB;
/****************************************************************/
struct _Batch/*多道处理中的道结构*/
{
PCB *pcb;/*该道当前正在处理的进程*/
struct _Batch *Next;/*下一道*/
};
typedef struct _Batch Batch;
/****************************************************************/
/*多道系统相关全局变量*/
PCB *ProcQueue = NULL;/*进程链表,按优先级从大到小排列*/
Batch *BatchQueue = NULL;/*系统多道链表*/
/****************************************************************/
/*动态优先权抢占式调度算法及相关函数声明*/
/****************************************************************/
int InitBatchs(int n);/*初始化多道系统,n为道数*/
int InsertProc(int prior, int time);/*向进程链表中按优先级大小插入一个新进程*/
int InsertIDLE();/*向进程队列中加入后备进程,当系统空闲时将被调入*/
int SortProcQueue();/*将进程链表按优先级从大到小排列*/
int AddBatch();/*增加系统道数*/
int DeleteBatch();/*减少系统道数*/
int UnSuspendProc(int id);/*解除ID为id的进程的挂起状态*/
int UpdateBatchs();/*多道系统根据进程链表进行更新,并将执行完毕的进程删除*/
int PassSeconds(int n);/*系统经过n秒后计算数据并进行优先级调度*/
/****************************************************************/
/*各函数的定义*/
/****************************************************************/
int InitBatchs(int n)
{
int i;
for (i=0; in; ++i)
{
AddBatch();
}
return (UpdateBatchs());
}
int InsertProc(int prior, int time)
{
static int sysid = 0;/*该系统已经加入过多少进程,此值将是新进程的ID*/
PCB *last,*now,*pcb;
pcb = (PCB*)malloc(sizeof(PCB));
if (pcb == NULL) return FALSE;
pcb-Prior = prior;
pcb-Time = time;
pcb-PID = (++sysid);
pcb-Sts = READY;
if (ProcQueue == NULL)/*如果进程队列为空*/
{
ProcQueue = pcb;
pcb-Next = NULL;
return TRUE;
}
last = ProcQueue;
now = last-Next;
if (pcb-Prior last-Prior)/*pcb将排在队头*/
{
pcb-Next = ProcQueue;
ProcQueue = pcb;
return TRUE;
}
while ((now != NULL) (pcb-Prior now-Prior))/*寻找插入位置*/
{
last = now;
now = last-Next;
}
last-Next = pcb;
pcb-Next = now;
return TRUE;
}
int InsertIDLE()
{
PCB *now = ProcQueue;
PCB *idle = (PCB*)malloc(sizeof(PCB));
if (idle == NULL) return FALSE;
idle-PID = -1;
idle-Prior = -1;
idle-Sts = SUSPEND;
idle-Time = -1;
idle-Next = NULL;
if (ProcQueue == NULL)
{
ProcQueue = idle;
return TRUE;
}
while(now-Next != NULL)
{
now = now-Next;
}
now-Next = idle;
return TRUE;
}
int SortProcQueue()
{ /*冒泡排序*/
PCB *last, *now;
int b = FALSE;/*上次遍历是否无交换产生*/
if (ProcQueue==NULL || ProcQueue-Next==NULL)/*如果链表中无进程或只有一个进程*/
return FALSE;
while (!b)
{
b = TRUE;
last=ProcQueue;
now=last-Next;
if (last-Prior now-Prior)
{
ProcQueue = now;
last-Next = now-Next;
now-Next = last;
b = FALSE;
last = ProcQueue;
now = last-Next;
}
while (now-Next!=NULL)
{
if ((now-Prior)(now-Next-Prior))
{
last-Next = now-Next;
now-Next = now-Next-Next;
last-Next-Next = now;
b = FALSE;
}
else
last = last-Next;
now = last-Next;
}
}
return TRUE;
}
int AddBatch()
{
Batch *bt = (Batch*)malloc(sizeof(Batch));
if (bt==NULL) return FALSE;
bt-Next = BatchQueue;
BatchQueue = bt;
bt-pcb = NULL;
return (InsertIDLE());
}
int DeleteBatch()
{
Batch *bt = BatchQueue;
PCB *last, *now;
if (BatchQueue==NULL || BatchQueue-Next==NULL)/*如果只剩最后一道则不删除*/
return FALSE;
if (ProcQueue==NULL || ProcQueue-Next==NULL)/*如果只有最后一个后备空闲进程*/
return FALSE;/**/
last = ProcQueue;
now = last-Next;
while (now-Next != NULL)/*查找到最后一个进程,该进程必定是后备空闲进程*/
{
last = now;
now = last-Next;
}
if (now==NULL || now-PID=0)/*未查找到后备进程*/
return FALSE;/**/
free(now);
last-Next = NULL;
BatchQueue = BatchQueue-Next;
free(bt);
return TRUE;
}
int UnSuspendProc(int id)
{
PCB *now = ProcQueue;
if (ProcQueue==NULL) return FALSE;
while (now != NULL)
{
if (now-PID == id)
{
now-Sts = READY;
return TRUE;
}
}
return FALSE;
}
int UpdateBatchs()
{
Batch *bt = BatchQueue;
PCB *last = ProcQueue, *now;
while (bt != NULL)
{
bt-pcb = NULL;
bt = bt-Next;
}
if (ProcQueue == NULL) return TRUE;
while (last-Sts==RUN last-PID=0 last-Time=0)
{
ProcQueue = ProcQueue-Next;
free(last);
last = ProcQueue;
}
now = last-Next;
while (now != NULL)
{
if (now-Sts==RUN now-PID=0 now-Time=0)/*如果该进程是运行中的一般进程并已执行完毕*/
{
last-Next = now-Next;
free(now);
}
else
last = last-Next;
now = last-Next;
}
bt = BatchQueue;
now = ProcQueue;
while (bt != NULL now != NULL)
{
bt-pcb = now;
now-Sts = RUN;
bt = bt-Next;
now = now-Next;
}
while (now != NULL)
{
if (now-Sts == RUN)
{
now-Sts = SUSPEND;
}
now = now-Next;
}
return TRUE;
}
int PassSeconds(int n)
{
static int time = 0;
int i=0, ProcEnd = FALSE;
PCB *pcb = ProcQueue;
Batch *bt = BatchQueue;
if (bt == NULL) return FALSE;
time += n;
if (time=TIME)
{
i = time/TIME;/*经过多少时间段*/
time = time%TIME;
}
while (bt != NULL)/*更新进程运行时间*/
{
if (bt-pcb-PID=0)
{
bt-pcb-Time -= n;
if (bt-pcb-Time = 0)/*进程结束*/
{
ProcEnd = TRUE;
}
}
bt = bt-Next;
}
if (i 0)
{
while (pcb != NULL)/*更新进程优先权(动态优先权)*/
{
if (pcb-Sts == RUN pcb-PID=0)/*运行的进程优先权降低*/
{
pcb-Prior -= i;
if (pcb-Prior 0)
pcb-Prior = 0;
}
else if (pcb-Sts == SUSPEND pcb-PID=0)/*挂起的进程优先权升高*/
pcb-Prior += i;
pcb = pcb-Next;
}
}
if (i0)
SortProcQueue();/*如果优先级有变动则重新排序*/
if (ProcEnd || i0)
{
UpdateBatchs();/*更新多道进程*/
}
return TRUE;
}
/****************************************************************/
/*图形界面相关函数*/
/****************************************************************/
/*表格的单位宽度和高度*/
#define WIDTH 64
#define HEIGHT 12
void *black=NULL;/*背景色方格,使用它擦出表格中的图形*/
int InitGraph()/*初始化图形界面*/
{
int GraphDriver; /* The Graphics device driver */
int GraphMode; /* The Graphics mode value */
int ErrorCode;
GraphDriver = DETECT; /* Request auto-detection */
initgraph( GraphDriver, GraphMode, "" );
ErrorCode = graphresult(); /* Read result of initialization*/
if( ErrorCode != grOk )
{ /* Error occured during init */
printf(" Graphics System Error: %s\n", grapherrormsg( ErrorCode ) );
getch();
return FALSE;
}
cleardevice();
black = (void*)malloc(imagesize(1,1,WIDTH-1,HEIGHT-1));
getimage(1,1,WIDTH-1,HEIGHT-1,black);
DrawFrame();
DrawData();
return TRUE;
}
int DrawFrame()/*画边框和表头*/
{
settextjustify(CENTER_TEXT, CENTER_TEXT);
gprintf(320, HEIGHT/2-1, "Multi-Batch System Emulation");
settextjustify(LEFT_TEXT, TOP_TEXT);
moveto(0,HEIGHT);
lineto(0,479);
lineto(639,479);
lineto(639,HEIGHT);
lineto(0,HEIGHT);
line(WIDTH*4,HEIGHT,WIDTH*4,479);
line(WIDTH*7,HEIGHT,WIDTH*7,479);
line(0,HEIGHT*2,639,HEIGHT*2);
line(0,HEIGHT*3,639,HEIGHT*3);
gprintf(HEIGHT*0+2,HEIGHT*1+2,"System Batchs");/*系统多道列表头*/
gprintf(HEIGHT*0+2,HEIGHT*2+2,"Batch");
gprintf(WIDTH*1+2,HEIGHT*2+2,"ProcID");
gprintf(WIDTH*2+2,HEIGHT*2+2,"Time");
gprintf(WIDTH*3+2,HEIGHT*2+2,"Prior");
gprintf(WIDTH*4+2,HEIGHT*1+2,"Suspended Processes");/*挂起队列列表头*/
gprintf(WIDTH*4+2,HEIGHT*2+2,"ProcID");
gprintf(WIDTH*5+2,HEIGHT*2+2,"Time");
gprintf(WIDTH*6+2,HEIGHT*2+2,"Prior");
gprintf(WIDTH*7+2,HEIGHT*1+2,"Ready Processes");/*就绪队列列表头*/
gprintf(WIDTH*7+2,HEIGHT*2+2,"ProcID");
gprintf(WIDTH*8+2,HEIGHT*2+2,"Time");
gprintf(WIDTH*9+2,HEIGHT*2+2,"Prior");
}
int DrawData()/*绘制系统数据*/
{
int numRun=0, numSus=0, numRed=0;/*运行挂起和就绪的进程各有多少*/
PCB* now = ProcQueue;
int x=0, y=0;
while (now != NULL)
{
switch(now-Sts)
{
case RUN:
x = WIDTH*1;
y = HEIGHT*(3+(numRun++));
break;
case SUSPEND:
x = WIDTH*4;
y = HEIGHT*(3+(numSus++));
break;
case READY:
x = WIDTH*7;
y = HEIGHT*(3+(numRed++));
break;
}
if (now-Sts==RUN)/*该进程为正在运行的进程*/
{
putimage(x-WIDTH+1,y+1,black,COPY_PUT);
gprintf(x-WIDTH+2,y+2,"%d",numRun);
}
if (now-PID=0)/*该进程不是后备进程*/
{
putimage(x+1,y+1,black,COPY_PUT);
gprintf(x+2,y+2,"%d",now-PID);
putimage(x+1+WIDTH,y+1,black,COPY_PUT);
gprintf(x+WIDTH+2,y+2,"%d",now-Time);
putimage(x+1+WIDTH*2,y+1,black,COPY_PUT);
gprintf(x+WIDTH*2+2,y+2,"%d",now-Prior);
}
else
{
putimage(x+1,y+1,black,COPY_PUT);
putimage(x+1+WIDTH,y+1,black,COPY_PUT);
putimage(x+1+WIDTH*2,y+1,black,COPY_PUT);
gprintf(x+2,y+2,"system idle process");
}
now = now-Next;
}
}
int DlgGetNum(char *buf,int l,int t,int r,int b,int gettime)
{
char ch;
int pos=0;
bar(l,t,r,b);
gprintf(l+10,t+5,"Add new Process");
if (gettime)
gprintf(l+10,t+20,"input the time:");
else
gprintf(l+10,t+20,"input the priority:");
while (1)
{
ch = getch();
if (ch == ENTER)/*如果输入了回车键*/
{
if(pos!=0)/*如果位置不在第一位(回车键不准第一个输入)*/
{
buf[pos]='\0';
break;
}
}
else if (ch='0' ch='9')
{
buf[pos++]=ch;
buf[pos]='\0';
}
else if (ch == ESC)
{
return FALSE;
}
else/*其他按键均按BackSpace处理*/
{
--pos;
buf[pos]='\0';
}
if (pos0)
{ pos=0; buf[pos]='\0';}
else if (pos4)/*最多输入4位数*/
{ pos=4; buf[pos]='\0';}
bar(l,t+35,r,t+47);
gprintf(l+50,t+35,buf);
}
return TRUE;
}
int NewProcDlg()
{
int l=200,t=150,r=380,b=200,pos=0,prior=0,time=0;
char buf[5],ch;
PCB *pcb;
void* bg = (void*)malloc(imagesize(l,t,r,b));
getimage(l,t,r,b,bg);
setfillstyle(1,2);
flushall();
/*******输入优先级**********/
if (!DlgGetNum(buf,l,t,r,b,FALSE))
goto exit;
prior = atoi(buf);
/*******输入时间**********/
pos=0;
buf[pos]='\0';
if (!DlgGetNum(buf,l,t,r,b,TRUE))
goto exit;
time = atoi(buf);
InsertProc(prior, time);
exit:
putimage(l,t,bg,COPY_PUT);
free(bg);
return TRUE;
}
int gprintf( int xloc, int yloc, char *fmt, ... )/*图形系统中的格式输出*/
{
va_list argptr; /* Argument list pointer */
char str[140]; /* Buffer to build sting into */
int cnt; /* Result of SPRINTF for return */
va_start( argptr, format ); /* Initialize va_ functions */
cnt = vsprintf( str, fmt, argptr ); /* prints string to buffer */
outtextxy( xloc, yloc, str ); /* Send string in graphics mode */
va_end( argptr ); /* Close va_ functions */
return( cnt ); /* Return the conversion count */
}
/****************************************************************/
/*main函数*/
int main()
{
clock_t start=0, end=0;
char kb;
InitBatchs(3);/*初始化为3道系统*/
InitGraph();
while (1)
{
start = end = clock();
while (!kbhit())
{
start = clock();
if ((start-end)/18.2 = 1)/*时间过了一秒*/
{
start = end = clock();
PassSeconds(1);
cleardevice();
DrawFrame();
DrawData();
}
}
kb = getch();
switch (kb)
{
case ESC:
closegraph();
return 0;
case 'w':
AddBatch();
UpdateBatchs();
cleardevice();
DrawFrame();
DrawData();
break;
case 's':
DeleteBatch();
UpdateBatchs();
cleardevice();
DrawFrame();
DrawData();
break;
case 'i':
NewProcDlg();
UpdateBatchs();
DrawFrame();
DrawData();
break;
}
}
return 0;
}
Q4: 求一个基于优先级的时间片轮转调度算法。实在是不太会做了,没思路。要求java 要求: (1)设系统
cpu进程调度模拟
四个队列是优先级队列(优先级高的在前面)
可以使用结构体做队列的节点
时间片轮转就是指定一个执行时间,时间一到就处理下一个进程,将当前进程进行状态转换(也就是换着状态需要向其放入相应的队列中,优先级队列)
理清头绪的话程序不算太复杂但也很麻烦
Q5: java如何获得每天8点这一时刻的long值?
java 每天获得8点这一时刻的long值,主要是使用timer类,来每隔一天执行,进行调度,如下代码:
package com.qiu.lin.he;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
public class Ceshi {
public static void main(String[] args) {
Timer timer = new Timer();//新建Timer类
Calendar cal = Calendar.getInstance();
// 每天定点执行
cal.set(Calendar.HOUR_OF_DAY, 8);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
timer.schedule(new TimerTask() {//每天执行输出时间
@Override
public void run() {
System.out.println(System.currentTimeMillis());
}
}, cal.getTime(), 24 * 60 * 60 * 1000);
}
}
轮转法调度java代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于轮转调度q=1、轮转法调度java代码的信息别忘了在本站进行查找喔。





