java磁盘调度代码 java 磁盘io

用JAVA实现时间片轮转调度算法你先用C写 , 然后做成DLL 。
再用java去调就好了 。
一般java做底层控制和调用都会这么做 。
就像io什么的,都是去调用C的代码完成的
一般java调用c写的dll代码都比较方便 。
c调用java的代码几乎不可能 。
求磁盘调度算法scan算法的java代码1、先来先服务算法(FCFS)First Come First Service
这是一种比较简单的磁盘调度算法 。它根据进程请求访问磁盘的先后次序进行调度 。此算法的优点是公平、简单,且每个进程的请求都能依次得到处理,不会出现某一进程的请求长期得不到满足的情况 。此算法由于未对寻道进行优化,在对磁盘的访问请求比较多的情况下,此算法将降低设备服务的吞吐量 , 致使平均寻道时间可能较长,但各进程得到服务的响应时间的变化幅度较小 。
先来先服务 (125)86.147.91.177.94.150.102.175.130
[java] view plain copy print?
优先级调度算法如何用JAVA实现没javajava磁盘调度代码的发段源代码给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/*进程结构*/
{
intPID;/*进程IDjava磁盘调度代码,ID为负数的进程为系统后备队列的作业*/
intTime;/*进程运行需要的时间*/
intPrior;/*进程的优先级java磁盘调度代码 , 越大越优先*/
StatusSts;/*状态*/
struct _Pcb *Next;/*指向本进程队列中下个进程的PCB*/
};
typedef struct _Pcb PCB;
/****************************************************************/
struct _Batch/*多道处理中的道结构*/
{
PCB*pcb;/*该道当前正在处理的进程*/
struct _Batch *Next;/*下一道*/
};
typedef struct _Batch Batch;
/****************************************************************/
/*多道系统相关全局变量*/
PCB *ProcQueue = NULL;/*进程链表 , 按优先级从大到小排列*/
【java磁盘调度代码 java 磁盘io】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-Priorlast-Prior)/*pcb将排在队头*/
{
pcb-Next = ProcQueue;
ProcQueue = pcb;
return TRUE;
}
while ((now != NULL)(pcb-Priornow-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-Priornow-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==RUNlast-PID=0last-Time=0)
{
ProcQueue = ProcQueue-Next;
free(last);
last = ProcQueue;
}
now = last-Next;
while (now != NULL)
{
if (now-Sts==RUNnow-PID=0now-Time=0)/*如果该进程是运行中的一般进程并已执行完毕*/
{
last-Next = now-Next;
free(now);
}
else
last = last-Next;
now = last-Next;
}
bt = BatchQueue;
now = ProcQueue;
while (bt != NULLnow != 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 (i0)
{
while (pcb != NULL)/*更新进程优先权(动态优先权)*/
{
if (pcb-Sts == RUNpcb-PID=0)/*运行的进程优先权降低*/
{
pcb-Prior -= i;
if (pcb-Prior0)
pcb-Prior = 0;
}
else if (pcb-Sts == SUSPENDpcb-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()/*初始化图形界面*/
{
intGraphDriver;/* The Graphics device driver*/
intGraphMode;/* 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)/*如果输入java磁盘调度代码了回车键*/
{
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_listargptr;/* 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;
}
Java 写的磁盘调度算法的扫描算法 输入数据报错 报错的是什么意思啊 其他数据试了很多都没问提示“I/O设备错误”java磁盘调度代码,一般都是由于硬盘坏道故障引起java磁盘调度代码的 。可以挂从盘用MHDD检测硬盘坏道java磁盘调度代码,如果你数据重要建议还是通过51Recovery这种专业机构进行数据恢复,数据恢复完成以后如果你的硬盘在保修期内就去保修;如果超过保修期java磁盘调度代码了就用MHDD自带的修理功能修复硬盘坏道 。要提醒的是,坏道故障比较忌讳继续通电尝试,这样问题会加重 。Hellogh2005,希望有帮助.到IT实验室,天天软件测试网泡泡
这段代码那里错了首先你的排序函数是不对的 , 具体错在你的交换a[i]和a[small]的值上,下面是我改的代码:
void SelectSort(int a[],int n)
{
int i,j,small;
int temp;//temp是需要的 。
for(i=0;in-1;i)
{
small=i;//设第i个数据元素关键字最小
for(j=i 1;jn;j)//寻找关键字最小的数据元素
if(a[j]a[small]) small=j;//记住最小元素的下标
if(small!=i)//当前最小元素的下标不为i是交换位置
{
temp = a[i]; //楼主错在这里
a[i]=a[small];
a[small]=temp;
}
}
}
其次电梯调度部分写得很混乱,错误很多,这里先来指出楼主的错误 。
void SCAN(int a[],int m,int direction){
int k=0,j=0,i;
int temp[m];//存放磁道的调度顺序号
//int cur;//临时变量,用于记录调度的起始磁道位置
if(direction==0)//磁头向磁道号增加的方向移动
{
for(;km;k)
{
if(b[k]=StartTrack)
{
//下面楼主开始犯错误了
//for(;k==m-1;k)temp[k]=b[k];//楼主的源代码,这里他犯了2个错误
//1、是for循环的条件,他写的k==m-1,如果是这样的话,那么循环一次也不会进行 。
//2、直接把b[k]上的值赋给了temp[k],注意此时k不是0...
//下面是修改后的代码
for(i=0;k 1m;i)
{
temp[i]=b[k i];
}
//在这里程序是不完整的 , 电梯这里只是走到了序号最大的地点,楼主的想法是想直接转到else部分,其实他没有理解if else到底是什么意思 。。。
}
else if(k==m-1)//楼主此处假设初始位置到顶了
{
direction=1;//省略部分代码//这里不知道楼主省了什么代码,不过单是一个direction=1是无法完成算法的,程序不会转到else部分
int n;
for(n=i;i0;i--,n)
{
temp[n]=b[i];
}
}
}
}
else//磁头向磁道号减少的方向移动
{
for(;km;k)
{
if(b[k]StartTrack)
{
//这里楼主犯错了for(;k==0;k--)temp[k]=b[k];//省略部分代码//理由同上
for(i=0;k0;i){
temp[i]=b[k-1-i]; //修改好的代码
}
//理由同上面相应部分
}
else if(k==m-1)
{
direction=0;//省略部分代码
//此处理由同前相应部分
}
}
}
}
总结一下,楼主对交换2个参量的值,条件判断语句, for循环方面的知识需要加强 。
下面贴出正确的电梯调度代码:
本人使用的C写的,使用C语言的话,需要替换相应的代码,如cout 换成相应的 printf()
经测试可以通过 。
#includeiostream
int StartTrack=143;
void SelectSort(int[],int);
void SCAN(int[],int,int);
void display(int[],int);
int get_Position(int[],int,int);
int scanUP(int[] , int , int[] , int , int );
int scanDOWN(int[] , int , int[] , int , int);
void main()
{
int a[10] = {11,99,200,176,56,33,188,210,34,46};
SelectSort( a , 10 );
SCAN( a , 10 , 1);
}
void SelectSort(int a[] , const int a_size)
{
int i,j,small;
int temp;
for(i=0;ia_size-1;i)
{
small=i;//设第i个数据元素关键字最小
for( j = i1 ; ja_size ; j)//寻找关键字最小的数据元素
if( a[j]a[small] ) small = j;//记住最小元素的下标
if( small != i)//当前最小元素的下标不为i是交换位置
{
temp = a[i];
a[i] = a[small];
a[small] = temp;
}
}
}
void display(int a[] ,const int a_size)
{
using namespace std;
for (int i = 0; ia_size ; i)
{
couta[i]" ";
}
cout"\n";
cin.get();
cin.get();
}
void SCAN(int a[] ,const int a_size , int direction)
{
int result_Array[10];
int channel_number = StartTrack;
int current_pos = get_Position( a , a_size , channel_number );
if( direction == 0){
int pos = scanUP( a , a_size , result_Array , 0 , current_pos);
scanDOWN( a , a_size ,result_Array , pos , current_pos );
}
else {
int pos = scanDOWN( a , a_size , result_Array , 0 , current_pos);
scanUP( a , a_size ,result_Array , pos , current_pos );
}
display(result_Array , a_size);
}
/*
get_Position
This function return the position that the value
of this position in array a[] is larger than the StartTrack
*/
int get_Position(int a[] ,int a_size , int channel_number)
{
for(int i = 0 ; ia_size ; i)
{
if( a[i]channel_number) return i;
}
return a_size;
}
/*
Scan up
a[] is the array to be scaned.
a_size is the size of the array.
result[] is the array to store the result.
result_tear is the last position that the position of result[] is empty.
*/
int scanUP(int a[] , int a_size , int result[] , int result_tear , int start_position)
{
int i = 0;
for( ; start_positionia_size ;i)
{
result[ result_teari] = a [start_positioni];
}
return iresult_tear;
}
/*
Scan down
a[] is the array to be scaned.
a_size is the size of the array.
result[] is the array to store the result.
result_tear is the last position that the position of result[] is empty.
*/
int scanDOWN(int a[] , int a_size , int result[] , int result_tear , int start_position)
{
int i = 0 ;
for( ; start_position - i0 ;i)
{
result[iresult_tear] = a [start_position - 1 - i];
}
return iresult_tear;
}
关于java磁盘调度代码和java 磁盘io的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读