当前位置:首页 » 课程大全 » 通用型操作系统课程设计

通用型操作系统课程设计

发布时间: 2021-01-31 18:24:51

⑴ 跪求操作系统课程设计一份

; boot.asm: ANOS fat12 软盘启动代码
; Larry Li, 2005.2.25
; 2005.3.19
; 整理注释

PosBuf equ 0700h
StackTop equ 07BF0h
BootStart equ 07C00h
;下面是内核的加载地址
SegKernel equ 0100h

RootBufEnd equ 02h
DataStart equ 04h
CursorPos equ 10h

; BOOT 会被 BIOS 载入到 00007C00h 处
org 7C00h

; 代码段
segment .text
; 16 位代码
bits 16

; start: 首先是跳过必须的 FAT 信息表执行后面的程序
Start:
jmp short Main
; 补一个字节的空指令
nop

; FAT12 信息
; 只是文件系统的描述信息
OEMName db 'ANOSDISK'
; 扇区大小(字节),应为 512
BytesPerSector dw 512
; 簇的扇区数,应为 2 的幂,FAT12 为 1
SectsPerCluster db 1
; 保留扇区,FAT12/16 应为 1
ReservedSectors dw 1
; FAT 结构数目,一般为 2
NumberOfFats db 2
; 根目录项目数,FAT12 为 224
MaxRootEntries dw 224
; 扇区总数,1.44M 软盘为 2880
TotalSectors dw 2880
; 设备类型,1.44M 软盘为 F0h
MediaDescriptor db 0f0h
; FAT 占用扇区数,9
SectorsPerFat dw 9
; 磁道扇区数,18
SectorsPerTrack dw 18
; 磁头数,2
NumberOfHeads dw 2
; 隐藏扇区,默认为 0
HiddenSectors dd 0
; FAT32 使用,0
TotalSectorsBig dd 0
;; 下面的内容为 FAT12/16 所有,和 FAT32 不同
; MS-DOS 使用,0
BootDrive db 0
; Windows NT 使用,0
Reserved db 0
; 附加的可启动标志,29h
ExtendSig db 029h
; 卷标序列号,00000000h
SerialNumber dd 00000000h
; 卷标,11 字节,必须用空格( 20h )补齐
VolumeLabel db 'ANOS FLOPPY'
; 文件系统标志,
FileSystem db 'FAT12 '

; Main: BOOT 主程序
Main:
; 初始化运行环境
xor ax,ax
mov ss,ax
mov bp,BootStart
mov sp,StackTop
push ss
pop ds

; LoadRootDirSector: 读取 FAT12 根目录项目扇区
LoadRootDirSector:
push ss
pop es

; 计算 ROOT 启始逻辑扇区
mov al,[BYTE bp+NumberOfFats]
; FAT 表数目
mul WORD [BYTE bp+SectorsPerFat]
; 乘上一个 FAT 表占用的扇区数
add ax,WORD [BYTE bp+HiddenSectors]
; 加上隐藏的扇区数
add ax,WORD [BYTE bp+ReservedSectors]
; 加上保留的扇区数
push ax
mov WORD [BYTE bp-DataStart],ax
; AX ROOT 项目的启始逻辑扇区, 保存

; 计算 ROOT 扇区数
mov ax,20h
mov cx,WORD [BYTE bp+MaxRootEntries]
mul cx
mov bx,WORD [BYTE bp+BytesPerSector]
add ax,bx
dec ax
div bx
mov cx,ax
; CX ROOT 扇区大小
add WORD [BYTE bp-DataStart],ax
; 更新数据区启始逻辑扇区
mul bx
; AX ROOT 总扇区字节大小
mov bx,PosBuf
; BX 缓存启始地址
add ax,bx
; AX 缓存尾地址
mov WORD [BYTE bp-RootBufEnd],ax
; 保存尾地址

pop ax
; 取出 ROOT 项目启始逻辑扇区
call ReadSectors
mov si,bx
; [ES:SI] 根目录内容

; SearchRootDirSector: 在根目录项目中搜索内核文件
SearchRootDirSector:
; [ES:SI] 为当前目录项
; 其头 11 个字节为文件名称
cmp [es:di],ch
; 如果目录项的第一个字节是0,这就是最后一个目录项
jz NotFound
push si
; 保存 SI rep cmpsb 时 SI 会改变
mov cx,11
; 比较前 11 个字节
mov di,FileName
; [DS:DI] 要载入的内核名称
rep cmpsb
; 比较 [ES:SI] [DS:DI]
pop si
; 恢复 [ES:SI] 为当前查对的目录项
je FoundKernel
add si,32
; [ES:SI] 指向下一个目录项
; 每个目录项 32 字节
cmp si,WORD [BYTE bp-RootBufEnd]
; 是否到根目录项目尾
jb SearchRootDirSector

; NotFound: 没有发现内核的处理
NotFound:
mov si,msgNotFound
call PutChars
jmp ReBoot

; FoundKernel: 发现内核后处理
FoundKernel:
; [ES:SI] 内核文件目录项
mov ax,[si+01ah]
push ax
; 内核文件启始簇(低)地址
; 目录项偏移 26(1ah) 为文件项目启始簇低地址
; 偏移 20(14h) 为高地址
; 由 FAT12 只是 12 位簇地址, 低地址 16 位足以

xor dx,dx
mov es,dx
mov ax,WORD [BYTE bp+ReservedSectors]
; DX:AX 第一个 FAT 表的启始逻辑扇区
mov bx,PosBuf
; [ES:BX] 读盘缓存
mov cx,WORD [BYTE bp+SectorsPerFat]
; CX FAT 表扇区数
call ReadSectors

pusha
mov si,msgLoadKernel
call PutChars
popa

mov ax,SegKernel
mov es,ax
xor bx,bx
; [ES:BX] 读盘缓存, 内核载入地址

pop ax
push ax
; 文件的第一个簇

; LoadKernel: 载入内核
LoadKernel:
; AX 当前簇
call ReadCluster
pop ax
; 取当前簇
add bx,0200h
; [ES:BX] 缓存地址增加 512 字节(1 个扇区)
; 下面开始查 FAT12 表项目
; 所以对于簇 n 其项目位于 n / 2 * 3 处
; n / 2 * 3 = n / 2 + n
; n 为偶, 在低 12 位
; n 为奇, 在高 12 位
mov di,ax
; BP DI 文件簇 n
shr di,01h
; DI n / 2
pushf
; 保存标志位, 供以后奇偶处理
add di,ax
; DI n / 2 + n
add di,PosBuf
; DI 加上 FAT12 表的启始地址
mov ax,[di]
; AX 一个 FAT12 组, 两个簇号
popf
; 根据 n / 2 奇偶判定
jc ShiftRight4
and ax,0fffh
; 取低 12 位
jmp IsTheEnd
ShiftRight4:
mov cl,4
shr ax,cl
; 高 12 位, 所以右移 4 位
IsTheEnd:
cmp ax,0ff8h
; 比较, ff8h - fffh 表示簇链末尾
jae ExecKernel
; 载入完毕, 跳转到内核地址
push ax
; 复制下一簇号
jmp LoadKernel

; ExecKernel: 运行内核
ExecKernel:
pusha
mov si,msgLoadKernelOK
call PutChars
popa

mov ah,3
xor bh,bh
int 10h
mov WORD [BYTE bp-CursorPos],dx
; 将当前光标位置写入 7df0h 7df1h
;
push word SegKernel
push word 00h
; 入栈供返回指令跳转
retf

; BadDisk: 显示错误启动信息,然后重启
BadDisk:
mov si,msgDiskError
call PutChars
; ReBoot: 重启
ReBoot:
mov si,msgAnyKey
call PutChars
xor ax,ax
int 16h
; 等待键盘按键
int 19h
; 重启

; ReadCluster: 读磁盘文件簇
; 读数据簇 AX 到 [ES:BX]
; CarryFlag == 1 错误
ReadCluster:
; 显示一个 .
push ax
mov ax,0e2eh
int 10h
pop ax

dec ax
dec ax
; 修正, 簇号 - 2
add ax, WORD [BYTE bp-DataStart]
; AX 数据的启始逻辑扇区
xor dx,dx
mov cx,01h

; ReadSectors: 读磁盘扇区
; 读 CX 个逻辑扇区(地址 DX:AX)到 [ES:BX]
; CarryFlag == 1 错误
ReadSectors:
pusha
push cx ; 保存读取扇区数
; 首先要将 DX:AX 逻辑扇区号转换为[驱动器号][磁头号][磁道号][扇区号]
; 根据:磁盘总扇区 = 磁道数 * 磁头数 * 扇区数
; 逻辑扇区 = (磁道号 * 磁头数 + 磁头号) * 扇区数 + 扇区号 - 1
; (注意:实际在磁道的扇区号是从 1 开始计数的,其他号从 0 开始)
; 那么:扇区号 = 逻辑扇区 % 磁道的扇区数 + 1
; 同样:含磁头计算的磁道号 = 逻辑扇区 / 磁道的扇区数
; 除掉磁头数,就是:磁道号 = 含磁头计算的磁道号 / 磁头数
; 所以:磁头号 = 含磁头计算的磁道号 % 磁头数
xchg ax,cx ; AX <=> CX
xchg ax,dx ; AX <=> DX
; AX:CX 逻辑扇区
xor dx,dx ; DX 清零
div WORD [BYTE bp+SectorsPerTrack] ; 除高位
; 计算得含磁头计算的磁道号的高位
xchg ax,cx ; 临时保存到 CX
; 此时余数 DX 与 AX 组成新数继续低位除
div WORD [BYTE bp+SectorsPerTrack] ; 除低位
; 余数 DX 为 0 开的扇区号
inc dx ; 修正为 1 开
xchg cx,dx ; CX <=> DX
; CX 为扇区号
; DX:AX 为含磁头计算的磁道号
div WORD [BYTE bp+NumberOfHeads] ; 继续除
; AX 为磁道号
; DX(DL) 为磁头号
mov dh,dl
; DH 磁头号
mov dl,[BYTE bp+BootDrive]
; DL 驱动器号
mov ch,al
; CX bit 8-15(CH) 磁道低 8 位
ror ah,2
; CX bit 6-7(AH bit 6-7) 磁道高 2 位
or cl,ah
; CX bit 0-5 扇区
pop ax
; AL 操作扇区数目
mov ah,02h
; AH 02h 读磁盘扇区
int 13h
; BIOS 13h 调用
; int 13h BIOS 功能
; 参数
; AH = 0x02 读磁盘扇区到内存
; AL 需要读出的扇区数量
; CH 磁道(柱面)号的低 8 位
; CL 开始扇区(0-5位),磁道号高 2 位(6-7)
; DH 磁头号
; DL 驱动器号
; ES:BX 指向数据缓存
; 返回
; 出错置 CF 标志位
; AH 状态 = 0x01
; AL 读取的扇区数
jc BadDisk

popa
ret

; PutChars: 打印字符串
; 入口参数 si
PutChars:
lodsb
or al,al
jz short Done
mov ah,0eh
mov bx,07h
int 10h
jmp short PutChars
Done:
retn

TheEnd:
db 0

msgLoadKernel db 'Loading ANOS',0
msgLoadKernelOK db 'OK!',0Dh,0Ah,0
msgNotFound db 'Cannot found ANOS kernel!',0Dh,0Ah,0
msgDiskError db 'Disk Error!',0Dh,0Ah,0
msgAnyKey db 'Press any key to reboot...',0Dh,0Ah,0

; 将 BOOT 映象对齐到 512 个字节
times 496-($-$$) db 0

FileName db 'ANOS SYS',0,0

BootPartition:
db 0

; 启动标志
BootSignature dw 0AA55h ; BootSector signature

⑵ 操作系统课程设计的内容简介

本书介绍了Linux操作系统机制,分析了部分Linux内核代码,并列出了操作系统针对性的实验;从Linux操作系统环境、系统调用、定时器、内核模块、进程调度、虚拟存储、文件系统,循序渐进到Linux内核的改动。Linux操作系统环境使用放在本书的附录中,对于没有学习过Linux操作系统命令的读者来说,需要掌握这方面的知识。
另一方面,作者本身也是程序员,对程序设计过程中的“创造性”有一定的体会。建议读者在使用本书时,大可不必循规蹈矩,读者可以用自己的思路学习Linux内核,这样既学到Linux源程序本身,更学到程序的“灵魂”。

⑶ 操作系统课程设计请高手们解决

呵呵,我这有个我们用的文件系统的,你看下能用不...基本上是C的代码吧。
#include <stdio.h>
#include <memory.h>
#include <string>
#include <iostream>
using namespace std;

struct FCB
{
char fname[16]; //文件名
int type; //1代表普通文件2代表目录文件0表示空文件
int size; //文件大小
int fatherBlockNum; //当前的父目录盘块号
int currentBlockNum; //当前的盘块

void initialize()
{
strcpy(fname,"\0");
type = 0;
size =0;
fatherBlockNum = currentBlockNum = 0;
}
};

/*常量设置*/
const char* FilePath = "C:\\myfiles";
const int BlockSize = 512; //盘块大小(可配置)
const int OPEN_MAX = 5; //能打开最多的文件数
const int BlockCount = BlockSize/sizeof(int); //盘块数
const int DiskSize = BlockSize*BlockCount; //磁盘大小
const int BlockFcbCount = BlockSize/sizeof(FCB);//目录文件的最多FCB数
//const int IOBUF_SIZE = 512;
//char IOBuffer[IOBUF_SIZE];
int OpenFileCount = 0;

struct OPENLIST //用户文件打开表
{
int files; //当前打开文件数
FCB f[OPEN_MAX]; //FCB拷贝
OPENLIST()
{
files=0;
for(int i=0;i<OPEN_MAX;i++){
f[i].fatherBlockNum=-1;//为分配打开
f[i].type=0;
}
}
};

/*-------------目录文件结构---------------*/
struct dirFile
{
struct FCB fcb[BlockFcbCount];
void init(int _FatherBlockNum,int _CurrentBlockNum,char *name)//父块号,当前块号,目录名
{
strcpy(fcb[0].fname,name); //本身的FCB
fcb[0].fatherBlockNum=_FatherBlockNum;
fcb[0].currentBlockNum=_CurrentBlockNum;
fcb[0].type=2; //标记目录文件
for(int i=1;i<BlockFcbCount;i++){
fcb[i].fatherBlockNum=_CurrentBlockNum; //标记为子项
fcb[i].type=0; // 标记为空白项
}
}
};

/**********************************************************************/
struct DISK
{
int FAT1[BlockCount]; //FAT1
int FAT2[BlockCount]; //FAT2
struct dirFile root; //根目录
char data[BlockCount-3][BlockSize];
void format()
{
memset(FAT1,0,BlockCount); //FAT1
memset(FAT2,0,BlockCount); //FAT2
FAT1[0]=FAT1[1]=FAT1[2]=-2; //0,1,2盘块号依次代表FAT1,FAT2,根目录区
FAT2[0]=FAT2[1]=FAT2[2]=-2; //FAT作备份
root.init(2,2,"G:\\");//根目录区
memset(data,0,sizeof(data));//数据区
}
};

/*-----------------全局变量--------------------------*/
FILE *fp; //磁盘文件地址
char * BaseAddr; //虚拟磁盘空间基地址
string currentPath="G:\\"; //当前路径
int current=2; //当前目录的盘块号
string cmd; //输入指令
struct DISK *osPoint; //磁盘操作系统指针
char command[16]; //文件名标识
struct OPENLIST* openlist; //用户文件列表指针

/*-----------函数事先申明--------------------*/
int format();
int mkdir(char *sonfname);
int rmdir(char *sonfname);
int create(char *name);
int listshow();
int delfile(char *name);
int changePath(char *sonfname);
int write(char *name);
int exit();
int open(char *file);
int close(char *file);
int read(char *file);
/*------------初始化-----------------------*/
int format()
{
current = 2;
currentPath="G:\\"; //当前路径
osPoint->format();//打开文件列表初始化
delete openlist;
openlist=new OPENLIST;
/*-------保存到磁盘上myfiles--------*/
fp = fopen(FilePath,"w+");
fwrite(BaseAddr,sizeof(char),DiskSize,fp);
fclose(fp);
printf("----------------------------------------------------------\n\n");
return 1;
}

/*-----------------------创建子目录-------------------*/
int mkdir(char *sonfname)
{
//判断是否有重名
//寻找空白子目录项
//寻找空白盘块号
//当前目录下增加该子目录项
//分配子目录盘块,并且初始化
//修改fat表
int i,temp,iFAT;
struct dirFile *dir; //当前目录的指针
if(current==2)
dir=&(osPoint->root);
else
dir=(struct dirFile *)(osPoint->data [current-3]);
/*--------为了避免该目录下同名文件夹--------*/
for(i = 1;i<BlockFcbCount;i++)
{
if(dir->fcb[i].type==2 && strcmp(dir->fcb[i].fname,sonfname)==0 )
{
printf("该文件夹下已经有同名的文件夹存在了!\n");
return 0;
}
}
//查找空白fcb序号
for(i=1;i<BlockFcbCount;i++)
{
if(dir->fcb[i].type==0)
break;
}

if(i==BlockFcbCount)
{
printf("该目录已满!请选择新的目录下创建!\n");
return 0;
}

temp=i;

for(i = 3;i < BlockCount;i++)
{
if(osPoint->FAT1[i] == 0)
break;
}

if(i == BlockCount)
{
printf("磁盘已满!\n");
return 0;
}

iFAT=i;

/*-------------接下来进行分配----------*/

osPoint->FAT1[iFAT]=osPoint->FAT2[iFAT] = 2; //2表示分配给下级目录文件
//填写该分派新的盘块的参数
strcpy(dir->fcb[temp].fname,sonfname);
dir->fcb[temp].type=2;
dir->fcb[temp].fatherBlockNum=current;
dir->fcb[temp].currentBlockNum=iFAT;
//初始化子目录文件盘块
dir=(struct dirFile*)(osPoint->data [iFAT-3]); //定位到子目录盘块号
dir->init (current,iFAT,sonfname);//iFAT是要分配的块号,这里的current用来指要分配的块的父块号
printf("---------------------------------------------------------------\n\n");
return 1;
}

/*-------删除当前目录下的文件夹--------*/
int rmdir(char *sonfname)
{
//if(子目录不存在) return error
//if(子目录不是空文件夹) return error
//回收子目录磁盘块号b(修改fat)
//回收子目录占据目录项
int i,temp,j;//确保当前目录下有该文件,并记录下该FCB下标
struct dirFile *dir; //当前目录的指针
if(current==2)
dir=&(osPoint->root);
else
dir=(struct dirFile *)(osPoint->data [current-3]);

for(i=1;i<BlockFcbCount;i++)
{ //查找该目录文件
if(dir->fcb[i].type==2 && strcmp(dir->fcb[i].fname,sonfname)==0)
{
break;
}
}

temp=i;

if(i==BlockFcbCount)
{
printf("当前目录下不存在该子目录!\n");
return 0;
}

j = dir->fcb[temp].currentBlockNum;
struct dirFile *sonDir; //当前子目录的指针
sonDir=(struct dirFile *)(osPoint->data [ j - 3]);

for(i=1;i<BlockFcbCount;i++) //查找子目录是否为空目录
{
if(sonDir->fcb[i].type!=0)
{
printf("该文件夹为非空文件夹,为确保安全,请清空后再删除!\n");
return 0;
}
}
/*开始删除子目录操作*/
osPoint->FAT1[j] = osPoint->FAT2[j]=0; //fat清空
char *p=osPoint->data[j-3]; //格式化子目录
memset(p,0,BlockSize);
dir->fcb[temp].initialize(); //回收子目录占据目录项
printf("---------------------------------------------------------------\n\n");
return 1;
}

/*-----------在当前目录下创建文本文件---------------*/
int create(char *name)
{
int i,iFAT;//temp,
int emptyNum = 0,isFound = 0; //空闲目录项个数
struct dirFile *dir; //当前目录的指针
if(current==2)
dir=&(osPoint->root);
else
dir=(struct dirFile *)(osPoint->data [current-3]);

//查看目录是否已满
//为了避免同名的文本文件
for(i=1;i<BlockFcbCount;i++)
{
if(dir->fcb[i].type == 0 && isFound == 0)
{
emptyNum = i;
isFound = 1;
}
else if(dir->fcb[i].type==1 && strcmp(dir->fcb[i].fname,name)==0 )
{
printf("无法在同一目录下创建同名文件!\n");
return 0;
}
}

if(emptyNum == 0)
{
printf("已经达到目录项容纳上限,无法创建新目录!\n");
return 0;
}

//查找FAT表寻找空白区,用来分配磁盘块号j
for(i = 3;i<BlockCount;i++)
{
if(osPoint->FAT1[i]==0)
break;
}
if(i==BlockCount)
{
printf("磁盘已满!\n");
return 0;
}
iFAT=i;

/*------进入分配阶段---------*/
//分配磁盘块
osPoint->FAT1[iFAT] = osPoint->FAT2[iFAT] = 1;
/*-----------接下来进行分配----------*/

//填写该分派新的盘块的参数
strcpy(dir->fcb[emptyNum].fname,name);
dir->fcb[emptyNum].type=1;
dir->fcb[emptyNum].fatherBlockNum=current;
dir->fcb[emptyNum].currentBlockNum=iFAT;
dir->fcb[emptyNum].size =0;
char* p = osPoint->data[iFAT -3];
memset(p,'#',BlockSize);
printf("----------------------------------------------------------------\n\n");
return 1;
}

/*-------查询子目录------------*/
int listshow()
{
int i,DirCount=0,FileCount=0;
//搜索当前目录
struct dirFile *dir; //当前目录的指针
if(current==2)
dir=&(osPoint->root);
else
dir=(struct dirFile *)(osPoint->data [current-3]);

for(i=1;i<BlockFcbCount;i++)
{
if(dir->fcb[i].type==1)
{ //查找普通文件
FileCount++;
printf("%s 文本文件.\n",dir->fcb[i].fname);
}
if(dir->fcb[i].type==2)
{ //查找目录文件
DirCount++;
printf("%s 文件夹.\n",dir->fcb[i].fname);
}
}
printf("\n该目录下共有 %d 个文本文件, %d 个文件夹\n\n",FileCount,DirCount);
printf("--------------------------------------------------------\n\n");
return 1;
}

/*---------在当前目录下删除文件-----------*/
int delfile(char *name)
{
int i,temp,j;
//确保当前目录下有该文件,并且记录下它的FCB下标
struct dirFile *dir; //当前目录的指针
if(current==2)
dir=&(osPoint->root);
else
dir=(struct dirFile *)(osPoint->data [current-3]);

for(i=1;i<BlockFcbCount;i++) //查找该文件
{
if(dir->fcb[i].type==1 && strcmp(dir->fcb[i].fname,name)==0)
{
break;
}
}

if(i==BlockFcbCount)
{
printf("当前目录下不存在该文件!\n");
return 0;
}

//从打开列表中删除
close(name);
temp=i;
/*开始删除文件操作*/
j = dir->fcb [temp].currentBlockNum ; //查找盘块号j
osPoint->FAT1[j]=osPoint->FAT2[j]=0; //fat1,fat2表标记为空白
char *p=osPoint->data[j - 3];
memset(p,0,BlockSize); //清除原文本文件的内容
dir->fcb[temp].initialize(); //type=0; //标记该目录项为空文件
printf("------------------------------------------------------------\n\n");
return 1;
}

/*--------------进入当前目录下的子目录--------------*/
int changePath(char *sonfname)
{
struct dirFile *dir; //当前目录的指针
if(current==2)
dir=&(osPoint->root);
else
dir=(struct dirFile *)(osPoint->data [current-3]);
/*回到父目录*/
if(strcmp(sonfname,"..")==0)
{
if(current==2)
{
printf("你现已经在根目录下!\n");
return 0;
}
current = dir->fcb[0].fatherBlockNum ;
currentPath = currentPath.substr(0,currentPath.size() - strlen(dir->fcb[0].fname )-1);
return 1;
}
/*进入子目录*/
int i,temp;
//确保当前目录下有该目录,并且记录下它的FCB下标
for(i = 1; i < BlockFcbCount; i++)
{ //查找该文件
if(dir->fcb[i].type==2 && strcmp(dir->fcb[i].fname,sonfname)==0 )
{
temp=i;
break;
}
}

if(i==BlockFcbCount)
{
printf("不存在该目录!\n");
return 0;
}

//修改当前文件信息
current=dir->fcb [temp].currentBlockNum ;
currentPath = currentPath+dir->fcb [temp].fname +"\\";
printf("-------------------------------------------------------------\n\n");
return 1;
}

/*--------System exit---------------------*/
int exit()
{
//将所有文件都关闭

//保存到磁盘上C:\myfiles
fp=fopen(FilePath,"w+");
fwrite(BaseAddr,sizeof(char),DiskSize,fp);
fclose(fp);
//释放内存上的虚拟磁盘
free(osPoint);
//释放用户打开文件表
delete openlist;
printf("---------------------------------------------------------\n\n");
return 1;
}

/*-------------在指定的文件里记录信息---------------*/
int write(char *name)
{
int i;
char *startPoint,*endPoint;
//在打开文件列表中查找 file(还需要考虑同名不同目录文件的情况!!!)
for(i=0;i<OPEN_MAX;i++)
{
if(strcmp(openlist->f [i].fname,name)==0 )
{
if(openlist->f[i].fatherBlockNum ==current)
{
break;
}
else
{
printf("该文件处于打开列表中,本系统只能改写当前目录下文件!\n");
return 0;
}
}
}

if(i==OPEN_MAX)
{
printf("该文件尚未打开,请先打开后写入信息!!\n");
return 0;
}

int active=i;
int fileStartNum = openlist->f[active].currentBlockNum - 3 ;
startPoint = osPoint->data[fileStartNum];
endPoint = osPoint->data[fileStartNum + 1];

printf("请输入文本以#号结束:\t");

char input;
while(((input=getchar())!='#'))
{
if(startPoint < endPoint-1)
{
*startPoint++ = input;
}
else
{
printf("达到单体文件最大容量!");
*startPoint++ = '#';
break;
}
}
return 1;
}

/*---------选择一个打开的文件读取信息----------*/
int read(char *file)
{
int i,fileStartNum;
char *startPoint,*endPoint;
//struct dirFile *dir;
//在打开文件列表中查找 file(还需要考虑同名不同目录文件的情况!!!)
for(i=0;i<OPEN_MAX;i++)
{
if(strcmp(openlist->f [i].fname,file)==0 )
{
if(openlist->f[i].fatherBlockNum ==current)
{
break;
}
else
{
printf("该文件处于打开列表中,本系统只能阅读当前目录下文件!\n");
return 0;
}
}
}

if(i==OPEN_MAX)
{
printf("该文件尚未打开,请先打开后读取信息!\n");
return 0;
}
int active=i;

//计算文件物理地址
fileStartNum = openlist->f[active].currentBlockNum - 3 ;
startPoint = osPoint->data[fileStartNum];
endPoint = osPoint->data[fileStartNum + 1];
//end_dir=(struct dirFile *)[BlockSize-1];

//q=(char *)end_dir;

printf("该文件的内容为: ");
while((*startPoint)!='#'&& (startPoint < endPoint))
{
putchar(*startPoint++);
}

printf("\n");
return 1;

}
/*当前目录下添加一个打开文件*/
int open(char *file)//打开文件
{
int i,FcbIndex;
//确保没有打开过该文件 = 相同名字 + 相同目录
for(i=0;i<OPEN_MAX;i++)
{
if(openlist->f[i].type ==1 && strcmp(openlist->f [i].fname,file)==0 &&openlist->f[i].fatherBlockNum == current)
{
printf("该文件已经被打开!\n");
return 0;
}
}

//确保有空的打开文件项
if(openlist->files == OPEN_MAX)
{
printf("打开文件数目达到上限!无法再打开新文件.\n");
return 0;
}

//确保当前目录下有该文件,并且记录下它的FCB下标
struct dirFile *dir; //当前目录的指针
if(current==2)
dir=&(osPoint->root);
else
dir=(struct dirFile *)(osPoint->data [current-3]);

for(i = 1;i< BlockFcbCount;i++)
{ //查找该文件
if(dir->fcb[i].type==1 && strcmp(dir->fcb[i].fname,file)==0 )
{
FcbIndex=i;
break;
}
}

if(i==BlockFcbCount)
{
printf("当前目录下不存在该文件!\n");
return 0;
}

//装载新文件进入打开文件列表,(FCB信息,文件数++) ??难道名字过不来?
openlist->f[OpenFileCount] = dir->fcb[FcbIndex]; //FCB拷贝
openlist->files ++;
printf("文件打开成功!\n");
OpenFileCount++;
return 1;
}

int close(char *file)
{
//释放该文件所占内存
//释放用户打开文件列表表项
int i;
//在打开文件列表中查找 file(还需要考虑同名不同目录文件的情况!!!)
for(i=0;i<OPEN_MAX;i++)
{
if((openlist->f [i].type = 1)&&
(strcmp(openlist->f [i].fname,file)==0))
{
if(openlist->f[i].fatherBlockNum == current)
{
break;
}
else
{
printf("该文件已打开,但未在当前目录下,无法关闭!\n");
return 0;
}
}
}

if(i==OPEN_MAX)
{
printf("该文件未在打开列表中!\n");
return 0;
}

int active=i;
openlist->files --;
openlist->f[active].initialize();
OpenFileCount--;
printf("该文件已关闭!\n");
return 1;
}

void main()
{

/*********************************************************************/
printf("-----Welcome To My Operate System Of File(FAT)-----\n");
//使用说明书
printf("\n 以下是使用说明书:\n");
printf("--------------------------------------------------------------\n");
printf("|| format :对磁盘格式化. || \n");
printf("|| exit :安全退出该文件系统,保存信息. || \n");
printf("|| mkdir dirname :创建子目录. || \n");
printf("|| rmdir dirname :删除子目录. || \n");
printf("|| ls dirname :显示当前目录下信息. || \n");
printf("|| cd dirname :更改当前目录. || \n");
printf("|| create filename :创建一个新文件,并且打开. || \n");
printf("|| write filename :选择一个打开的文件写入信息 || \n");
printf("|| read filename :选择一个打开的文件读取信息. || \n");
printf("|| rm filename :删除文件. || \n");
printf("|| open filename :打开文件. || \n");
printf("|| close filename :关闭文件. || \n");
printf("-------------------------------------------------------------\n\n");
//创建用户文件打开表
openlist=new OPENLIST;
//申请虚拟空间并且初始化
BaseAddr=(char *)malloc(DiskSize);
//虚拟磁盘初始化
osPoint=(struct DISK *)(BaseAddr);
//加载磁盘文件
if((fp=fopen(FilePath,"r"))!=NULL){
fread(BaseAddr,sizeof(char),DiskSize,fp);
printf("加载磁盘文件( %s )成功,现在可以进行操作了!\n\n",FilePath);
}
else{
printf("这是你第一次使用该文件管理系统!\t正在初始化...\n");
format();
printf("初始化已经完成,现在可以进行操作了!\n\n");
}

printf("--------------------------------------------------------------\n\n");
while(1){
cout<<currentPath;
cin>>cmd;
if(cmd=="format"){
format();
}
else if(cmd=="mkdir"){
cin>>command;
mkdir(command);
}
else if(cmd=="rmdir"){
cin>>command;
rmdir(command);
}
else if(cmd=="ls"){
listshow();
}
else if(cmd=="cd"){
cin>>command;
changePath(command);
}
else if(cmd=="create"){
cin>>command;
create(command);
}

else if(cmd=="write"){
cin>>command;
write(command);
}
else if(cmd=="read"){
cin>>command;
read(command);
}
else if(cmd=="rm"){
cin>>command;
delfile(command);
}
else if(cmd=="open"){
cin>>command;
open(command);
}
else if(cmd=="close"){
cin>>command;
close(command);
}
else if(cmd=="exit"){
exit();
break;
}
else cout<<"无效指令,请重新输入:"<<endl;
}
printf("Thank you for using my file system!\n");
}
可以运行的哈~~

⑷ 操作系统课设。急急急~~~~~

1、了解UNIX的命令及使用格式,熟悉UNIX/LINUX的常用基本命令,练习并掌握UNIX提供的vi编辑版器来编译C程序,学会利用权gcc、gdb编译、调试C程序。
2、用fork( )创建一个进程,再调用exec( )用新的程序替换该子进程的内容,利用wait( )来控制进程执行顺序。
还要任务书包括以下东西:
设计思想;
3)各模块的伪码算法;
4)函数的调用关系图;
5)测试结果;
6)设计总结;

⑸ 操作系统课程设计(linux)

我也遇到过这个问题,安装的时候你没有装图形用户终端(似乎是叫回Xwindow)。之前有叫你打勾安答装的。所以最后就只有命令行界面了(其实这个界面也可以解,但我不大会)。重回到开头找到打勾选项去勾选相应图形界面安装!

⑹ 操作系统课程设计 (包括进程管理、进程的同步和互斥、存储管理)

- 课程设计的计算机操作系统程序
课程概述

计算机操作系统是中央广播电视大学计算机科学与技术专业(本科),系统设置必修课程。教学总时数72.4学分,开设一学期。前课程,计算机组成原理,面向对象编程和数据结构。

计算机操作系统课程是计算机专业的课程,通过学习,使学生掌握电脑作业系统的设计和组成的基本原则之一;计算机操作系统的基本概念和新的概念,术语和术语;了解计算机的发展,操作系统的功能和设计技巧和方法,基本操作使用最常用的计算机操作系统(DOS,Windows,UNIX或Linux)的。

?课程内容

主要内容包括:概述电脑的操作系统,作业管理,文件管理,存储管理,输入输出设备管理,工艺和管理处理器,操作系统结构和编程。

二,系统的教学内容和教学要求

章概述操作系统的中

教学内容:

操作系统的定义和发展形成的操作系统和五个主要类型,操作系统五大功能特性的操作系统的性能,配置的操作系统,“生成”的概念

教学要求:

主:什么是操作系统;知道五类和五功能的操作系统;

至少掌握:掌握操作系统的安装,使用和维护的实际怀抱;

理解:如何理解一个初步的了解,熟悉和解剖学的人机交互界面的操作系统

任务的作业管理

教学内容如下:

的特点,人机界面的发展;操作系统的shell语言的第一,第二和第三代接口的发展特点,基本键盘命令和系统调用任务调度算法; 教学要求:

主的人机界面设计

大师:掌握基本的作业系统人机界面的设计思路;

理解:传统的接口界面

章文件管理的

教学内容:

文件管理任务和功能的操作系统文件的结构和分类的物理结构和逻辑结构的文件,文件目录结构,文件访问控制和安全机制,文件系统模型结构;

教学要求:

水平:基本的文件访问控制和系统管理;
>掌握的文件系统目录分类管理功能;

理解:文件系统的程序设计

的章内部存储管理

教学内容:

内存分区,分页,子段的管理理念;物理地址和逻辑地址内存“扩展”技术;存储管理,支柱存储管理的内存分配算法的

教学的要求:

掌握基本配置:内存管理和调度方法;

主:主不同的分区存储管理,分页和分段方法;

有关:有效利用的内存空间

第五章输入和输出设备管理器的教学内容:

的输入和输出设备的功能分类;独占的,共享的,虚拟装置的管理功能;输入和输出设备的处理程序;管理策略的输入和输出设备;

教学要求:

法师:法师的输入和输出设备的管理特性;

法师:法师分类设计方法的输入和输出设备;

明白了:

编程元素的输入和输出设备处理程序第

教学内容的低级别的处理器管理:

操作系统的核心功能,“过程”的概念,过程的并发和并行的基本状态的转换的过程;进程调度算法进程同步和互斥过程PV操作,“锁”的概念;

教学要求:

大师:在操作系统内核运行的基本概念“过程“;

掌握的基本转换过程中的状态和特征;

理解:操作系统

教学内容,进程调度算法的编程方案的结构

BR />第七章:

操作分层的模块化的系统结构设计和操作系统的测试;的

教学的要求:

本章教学基本要求:了解基本的设计思路和方法现代计算机操作系统

三,教学媒体

本课程使用的教学媒体:文字材料,视频材料,网络教学和辅导。

1。文字材料

计算机操作系统(2)武企业万元清华大学出版社

注:本课程实验的主要教材。

文字教材过程中的主要传播媒介。准备的文字材料,同时保持先进性,科学的学科体系,这两种作业系统的理论,技术,实现了一体化的三个强调的能力。

2。视频教材

该课程16节和视频,每讲50分钟,讲授的课程集中困难,科目汇总。为了帮助学生理解操作系统的整体概念和思想,伍启元教授扬声器。

当然,视频与相应的文字材料,注重艺术表达播放视频教材,教学形象化。

3。

在线教学网上教学和指导,咨询与上述有机介质方面的作用:(1)释放的教学和指导性文件,课程公告,咨询,参考材料;(2)根据工程进度教学,心理咨询聊天室发表的一篇文章“自我测试题(3)实时Q&A,一天到一天的课程论坛Q;(4)开展网上教师培训与教学研讨会。

文字材料的基础上,对学生的学习,视频教科书的补充文字材料,在线咨询是一个方便的教学和学习方式的互动。总之,分工和各种媒体,让学生有更大的自主学习空间,以方便学生自由选择,自主学习,提高学生的自我学习能力。

教学安排建议

当然主要教科书和课程实验教学安排建议

教学点,请根据中央电大统一安排课程,面对面辅导的要求,如表1所示。

表1的主要教科书和课程实验教学安排建议

每周教学内容小时的实验内容推荐小时

操作系统的教学安排概述

2操作系统定义了五种类型, 5 4

三人人机界面管理Linux的实践准备1

四个工作管理任务调度4

五个文件管理的任务和功能的Linux操作系统命令的逻辑结构和物理结构4

7个存储管理任务和功能2命令解释器4

九编制2

八分分配存储管理段4

分配的存储管理作业调度模拟编程的六个文件10设备管理的任务和职能

11种设备,技术和管理存储分配管理设计4

过程的定义和特征4 13进程调度和通信进程调度模拟编程 p> 15操作系统级模块结构僵局的产生和处理14 26 4

(总复习)4

共56条16

课程视频内容,示于表2。

章教学内容表2视频教材课程小时的视频时间分配

操作系统提供了一个概述8小时4

运营管理8小时2

文件管理2

8小时的存储管理8小时

5个设备管理器

6过程管理8小时10小时4

7操作系统的系统程序结构6小时0

56小时16

2在线咨询在线咨询内容

包括教学文件,课程辅导,网络教室。充分利用网络资源,和偶尔的在线课程相关的辅导材料,定期,根据教学在线辅导和考试Q&A活动,适当安排的需要。具体安排如下:



包括课程介绍,教师,教学大纲,教学设计,教学档案。

?课程辅导

包括课程学习和答案,专题辅导,习题和答案,自我测试,评估说明,网上还提供了教师讲课教案教学点的教学使用。

?网络课堂

包括直播课堂和IP课件。

基于网络的教学活动:中央广播电视大学一般集中在每学期安排的实时在线辅导学生,教师的教学和研究活动。具体的时间表,每学期上发布的TVU的网上家园。

?论坛:每天的日常应答的过程中。

课程的课堂直播第一学期,通过教育电视台播出,安排四次直播课堂,每次50分钟。的第一堂课3个教学点,难点的教学和演讲后代表咨询审查的辅导和考试说明的过程中反映的共性问题。直播课堂挂在网页上的内容。

工作

课程形成性评估书,当然工作量。工作成绩计入课程成绩。中央电大的工作,不时抽查,检查审查和完成作业。

课程考试,请参阅“中央广播电视大学计算机操作系统课程评估的指示。建议

五,教学方法?教学建议

(1)计算机操作系统是一个实用的课程。其特点是概念多,涉及范围广。要求教学辅导深和混乱的概念来进行详细说明,并详细描述每章的重点,管理和控制的调度算法技能。

(2)注重培养学生熟悉的操作系统,以及在维护操作系统的问题进行分析,并在实验中解决问题的能力。

?建议

(1)从宏观和微观把握学习操作系统。在宏观上,要认识到在计算机系统中的操作系统的地位清除操作系统的整体结构;微观方面应把握的操作系统是管理计算机资源(过程中,处理器,内存,文件,设备),了解概念,原理和技术。

(2)操作系统是计算机技术和管理技术相结合的联想日常生活学习重复熟悉的样品管理实现运营系统的管理方法,以加深对问题的理解。
(3)要注意加强自我学习的能力,有能力实现这一目标的“学习”的文化。

⑺ 求一个操作系统课程设计

#include<iostream>
using namespace std;
#define MAX 10
struct task_struct
{
char name[10]; /*进程名称*/
int number; /*进程编号*/
float come_time; /*到达时间*/
float run_begin_time; /*开始运行时间*/
float run_time; /*运行时间*/
float run_end_time; /*运行结束时间*/
int priority; /*优先级*/
int order; /*运行次序*/
int run_flag; /*调度标志*/
}tasks[MAX];
int counter; /*实际进程个数*/
int fcfs(); /*先来先服务*/
int ps(); /*优先级调度*/
int sjf(); /*短作业优先*/
int hrrn(); /*响应比高优先*/
int pinput(); /*进程参数输入*/
int poutput(); /*调度结果输出*/

void main()
{ int option;
pinput();
printf("请选择调度算法(0~4):\n");
printf("1.先来先服务\n");
printf("2.优先级调度\n");
printf(" 3.短作业优先\n");
printf(" 4.响应比高优先\n");
printf(" 0.退出\n");
scanf("%d",&option);
switch (option)
{ case 0:
printf("运行结束。\n");
break;
case 1:
printf("对进程按先来先服务调度。\n\n");
fcfs();
poutput();
break;
case 2:
printf("对进程按优先级调度。\n\n");
ps();
poutput();
break;
case 3:
printf("对进程按短作业优先调度。\n\n");
sjf();
poutput();
break;
case 4:
printf("对进程按响应比高优先调度。\n\n");
hrrn();
poutput();
break;
}
}
int fcfs() /*先来先服务*/
{
float time_temp=0;
int i;
int number_schel;
time_temp=tasks[0].come_time;
for(i=0;i<counter;i++)
{
tasks[i].run_begin_time=time_temp;
tasks[i].run_end_time=tasks[i].run_begin_time+tasks[i].run_time;
tasks[i].run_flag=1;
time_temp=tasks[i].run_end_time;
number_schel=i;
tasks[number_schel].order=i+1;
}
return 0;
}

int ps() /*优先级调度*/
{
float temp_time=0;
int i=0,j;
int number_schel,temp_counter;
int max_priority;
max_priority=tasks[i].priority;
j=1;
while ((j<counter)&&(tasks[i].come_time==tasks[j].come_time))
{
if (tasks[j].priority>tasks[i].priority)
{
max_priority=tasks[j].priority;
i=j;
}
j++;
} /*查找第一个被调度的进程*/
/*对第一个被调度的进程求相应的参数*/
number_schel=i;
tasks[number_schel].run_begin_time=tasks[number_schel].come_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
tasks[number_schel].run_flag=1;
temp_time=tasks[number_schel].run_end_time;
tasks[number_schel].order=1;
temp_counter=1;
while (temp_counter<counter)
{
max_priority=0;
for(j=0;j<counter;j++)
{ if((tasks[j].come_time<=temp_time)&&(!tasks[j].run_flag))
if (tasks[j].priority>max_priority)
{
max_priority=tasks[j].priority;
number_schel=j;
}
} /*查找下一个被调度的进程*/
/*对找到的下一个被调度的进程求相应的参数*/
tasks[number_schel].run_begin_time=temp_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
tasks[number_schel].run_flag=1;
temp_time=tasks[number_schel].run_end_time;
temp_counter++;
tasks[number_schel].order=temp_counter;

}return 0;
}

int sjf() /*短作业优先*/
{
float temp_time=0;
int i=0,j;
int number_schel,temp_counter;
float run_time;
run_time=tasks[i].run_time;
j=1;
while ((j<counter)&&(tasks[i].come_time==tasks[j].come_time))
{
if (tasks[j].run_time<tasks[i].run_time)
{
run_time=tasks[j].run_time;
i=j;
}
j++;
} /*查找第一个被调度的进程*/
/*对第一个被调度的进程求相应的参数*/
number_schel=i;
tasks[number_schel].run_begin_time=tasks[number_schel].come_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
tasks[number_schel].run_flag=1;
temp_time=tasks[number_schel].run_end_time;
tasks[number_schel].order=1;
temp_counter=1;
while (temp_counter<counter)
{
for(j=0;j<counter;j++)
{
if((tasks[j].come_time<=temp_time)&&(!tasks[j].run_flag))

}

for(j=0;j<counter;j++)
{ if((tasks[j].come_time<=temp_time)&&(!tasks[j].run_flag))
if(tasks[j].run_time<run_time)
{run_time=tasks[j].run_time;
number_schel=j;
}
}
/*查找下一个被调度的进程*/
/*对找到的下一个被调度的进程求相应的参数*/
tasks[number_schel].run_begin_time=temp_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
tasks[number_schel].run_flag=1;
temp_time=tasks[number_schel].run_end_time;
temp_counter++;
tasks[number_schel].order=temp_counter;
}return 0;
}

int hrrn() /*响应比高优先*/
{ int j,number_schel,temp_counter;
float temp_time,respond_rate,max_respond_rate;
/*第一个进程被调度*/
tasks[0].run_begin_time=tasks[0].come_time;
tasks[0].run_end_time=tasks[0].run_begin_time+tasks[0].run_time;
temp_time=tasks[0].run_end_time;
tasks[0].run_flag=1;
tasks[0].order=1;
temp_counter=1;
/*调度其他进程*/
while(temp_counter<counter)
{
max_respond_rate=0;
for(j=1;j<counter;j++)
{
if((tasks[j].come_time<=temp_time)&&(!tasks[j].run_flag))
{ respond_rate=(temp_time-tasks[j].come_time)/tasks[j].run_time;
if (respond_rate>max_respond_rate)
{
max_respond_rate=respond_rate;
number_schel=j;
}
}
} /*找响应比高的进程*/
tasks[number_schel].run_begin_time=temp_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
temp_time=tasks[number_schel].run_end_time;
tasks[number_schel].run_flag=1;
temp_counter+=1;
tasks[number_schel].order=temp_counter;
}
return 0;
}
int pinput() /*进程参数输入*/
{ int i;
printf("please input the process counter:\n");
scanf("%d",&counter);

for(i=0;i<counter;i++)
{ printf("******************************************\n");
printf("please input the process of %d th :\n",i+1);
printf("please input the name:\n");
scanf("%s",tasks[i].name);
printf("please input the number:\n");
scanf("%d",&tasks[i].number);
printf("please input the come_time:\n");
scanf("%f",&tasks[i].come_time);
printf("please input the run_time:\n");
scanf("%f",&tasks[i].run_time);
printf("please input the priority:\n");
scanf("%d",&tasks[i].priority);
tasks[i].run_begin_time=0;
tasks[i].run_end_time=0;
tasks[i].order=0;
tasks[i].run_flag=0;
}
return 0;
}
int poutput() /*调度结果输出*/
{
int i;
float turn_round_time=0,f1,w=0;
printf("name number come_time run_time run_begin_time run_end_time priority order turn_round_time\n");
for(i=0;i<counter;i++)
{
f1=tasks[i].run_end_time-tasks[i].come_time;
turn_round_time+=f1;
w+=(f1/tasks[i].run_time);
printf(" %s, %d, %5.3f, %5.3f, %5.3f, %5.3f, %d, %d, %5.3f\n",tasks[i].name,tasks[i].number,tasks[i].come_time,tasks[i].run_time,tasks[i].run_begin_time,tasks[i].run_end_time,tasks[i].priority,tasks[i].order,f1);
}
printf("average_turn_round_timer=%5.2f\n",turn_round_time/counter);
printf("weight_average_turn_round_timer=%5.2f\n",w/counter);
return 0;
}

如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!

⑻ 求操作系统课程设计

#include<iostream>
using namespace std;
#define MAX 10
struct task_struct
{
char name[10]; /*进程名称*/
int number; /*进程编号*/
float come_time; /*到达时间*/
float run_begin_time; /*开始运行时间*/
float run_time; /*运行时间*/
float run_end_time; /*运行结束时间*/
int priority; /*优先级*/
int order; /*运行次序*/
int run_flag; /*调度标志*/
}tasks[MAX];
int counter; /*实际进程个数*/
int fcfs(); /*先来先服务*/
int ps(); /*优先级调度*/
int sjf(); /*短作业优先*/
int hrrn(); /*响应比高优先*/
int pinput(); /*进程参数输入*/
int poutput(); /*调度结果输出*/

void main()
{ int option;
pinput();
printf("请选择调度算法(0~4):\n");
printf("1.先来先服务\n");
printf("2.优先级调度\n");
printf(" 3.短作业优先\n");
printf(" 4.响应比高优先\n");
printf(" 0.退出\n");
scanf("%d",&option);
switch (option)
{ case 0:
printf("运行结束。\n");
break;
case 1:
printf("对进程按先来先服务调度。\n\n");
fcfs();
poutput();
break;
case 2:
printf("对进程按优先级调度。\n\n");
ps();
poutput();
break;
case 3:
printf("对进程按短作业优先调度。\n\n");
sjf();
poutput();
break;
case 4:
printf("对进程按响应比高优先调度。\n\n");
hrrn();
poutput();
break;
}
}
int fcfs() /*先来先服务*/
{
float time_temp=0;
int i;
int number_schel;
time_temp=tasks[0].come_time;
for(i=0;i<counter;i++)
{
tasks[i].run_begin_time=time_temp;
tasks[i].run_end_time=tasks[i].run_begin_time+tasks[i].run_time;
tasks[i].run_flag=1;
time_temp=tasks[i].run_end_time;
number_schel=i;
tasks[number_schel].order=i+1;
}
return 0;
}

int ps() /*优先级调度*/
{
float temp_time=0;
int i=0,j;
int number_schel,temp_counter;
int max_priority;
max_priority=tasks[i].priority;
j=1;
while ((j<counter)&&(tasks[i].come_time==tasks[j].come_time))
{
if (tasks[j].priority>tasks[i].priority)
{
max_priority=tasks[j].priority;
i=j;
}
j++;
} /*查找第一个被调度的进程*/
/*对第一个被调度的进程求相应的参数*/
number_schel=i;
tasks[number_schel].run_begin_time=tasks[number_schel].come_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
tasks[number_schel].run_flag=1;
temp_time=tasks[number_schel].run_end_time;
tasks[number_schel].order=1;
temp_counter=1;
while (temp_counter<counter)
{
max_priority=0;
for(j=0;j<counter;j++)
{ if((tasks[j].come_time<=temp_time)&&(!tasks[j].run_flag))
if (tasks[j].priority>max_priority)
{
max_priority=tasks[j].priority;
number_schel=j;
}
} /*查找下一个被调度的进程*/
/*对找到的下一个被调度的进程求相应的参数*/
tasks[number_schel].run_begin_time=temp_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
tasks[number_schel].run_flag=1;
temp_time=tasks[number_schel].run_end_time;
temp_counter++;
tasks[number_schel].order=temp_counter;

}return 0;
}

int sjf() /*短作业优先*/
{
float temp_time=0;
int i=0,j;
int number_schel,temp_counter;
float run_time;
run_time=tasks[i].run_time;
j=1;
while ((j<counter)&&(tasks[i].come_time==tasks[j].come_time))
{
if (tasks[j].run_time<tasks[i].run_time)
{
run_time=tasks[j].run_time;
i=j;
}
j++;
} /*查找第一个被调度的进程*/
/*对第一个被调度的进程求相应的参数*/
number_schel=i;
tasks[number_schel].run_begin_time=tasks[number_schel].come_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
tasks[number_schel].run_flag=1;
temp_time=tasks[number_schel].run_end_time;
tasks[number_schel].order=1;
temp_counter=1;
while (temp_counter<counter)
{
for(j=0;j<counter;j++)
{
if((tasks[j].come_time<=temp_time)&&(!tasks[j].run_flag))
{ run_time=tasks[j].run_time;number_schel=j;break;}
}

for(j=0;j<counter;j++)
{ if((tasks[j].come_time<=temp_time)&&(!tasks[j].run_flag))
if(tasks[j].run_time<run_time)
{run_time=tasks[j].run_time;
number_schel=j;
}
}
/*查找下一个被调度的进程*/
/*对找到的下一个被调度的进程求相应的参数*/
tasks[number_schel].run_begin_time=temp_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
tasks[number_schel].run_flag=1;
temp_time=tasks[number_schel].run_end_time;
temp_counter++;
tasks[number_schel].order=temp_counter;
}return 0;
}

int hrrn() /*响应比高优先*/
{ int j,number_schel,temp_counter;
float temp_time,respond_rate,max_respond_rate;
/*第一个进程被调度*/
tasks[0].run_begin_time=tasks[0].come_time;
tasks[0].run_end_time=tasks[0].run_begin_time+tasks[0].run_time;
temp_time=tasks[0].run_end_time;
tasks[0].run_flag=1;
tasks[0].order=1;
temp_counter=1;
/*调度其他进程*/
while(temp_counter<counter)
{
max_respond_rate=0;
for(j=1;j<counter;j++)
{
if((tasks[j].come_time<=temp_time)&&(!tasks[j].run_flag))
{ respond_rate=(temp_time-tasks[j].come_time)/tasks[j].run_time;
if (respond_rate>max_respond_rate)
{
max_respond_rate=respond_rate;
number_schel=j;
}
}
} /*找响应比高的进程*/
tasks[number_schel].run_begin_time=temp_time;
tasks[number_schel].run_end_time=tasks[number_schel].run_begin_time+tasks[number_schel].run_time;
temp_time=tasks[number_schel].run_end_time;
tasks[number_schel].run_flag=1;
temp_counter+=1;
tasks[number_schel].order=temp_counter;
}
return 0;
}
int pinput() /*进程参数输入*/
{ int i;
printf("please input the process counter:\n");
scanf("%d",&counter);

for(i=0;i<counter;i++)
{ printf("******************************************\n");
printf("please input the process of %d th :\n",i+1);
printf("please input the name:\n");
scanf("%s",tasks[i].name);
printf("please input the number:\n");
scanf("%d",&tasks[i].number);
printf("please input the come_time:\n");
scanf("%f",&tasks[i].come_time);
printf("please input the run_time:\n");
scanf("%f",&tasks[i].run_time);
printf("please input the priority:\n");
scanf("%d",&tasks[i].priority);
tasks[i].run_begin_time=0;
tasks[i].run_end_time=0;
tasks[i].order=0;
tasks[i].run_flag=0;
}
return 0;
}
int poutput() /*调度结果输出*/
{
int i;
float turn_round_time=0,f1,w=0;
printf("name number come_time run_time run_begin_time run_end_time priority order turn_round_time\n");
for(i=0;i<counter;i++)
{
f1=tasks[i].run_end_time-tasks[i].come_time;
turn_round_time+=f1;
w+=(f1/tasks[i].run_time);
printf(" %s, %d, %5.3f, %5.3f, %5.3f, %5.3f, %d, %d, %5.3f\n",tasks[i].name,tasks[i].number,tasks[i].come_time,tasks[i].run_time,tasks[i].run_begin_time,tasks[i].run_end_time,tasks[i].priority,tasks[i].order,f1);
}
printf("average_turn_round_timer=%5.2f\n",turn_round_time/counter);
printf("weight_average_turn_round_timer=%5.2f\n",w/counter);
return 0;
}

⑼ 操作系统课程设计

最近没什么写日记,想写,但是对于感情方面的写多了没意思,变得庸俗。于是,我决定来一个科学的日志。下面就写写我在操作系统那门课中的一个实验:银行家算法。自从学了java,在我对游戏和网络情有独钟的基础上,我抛弃了c语言,因此,这个实验我是用java来编写的。线程我没学,所以就简单地写几个输入,然后得出结果。
银行家算法大家懂吗?我想,我们学院的都应该懂的。简单地来讲,就是假设系统有n种资源,每种资源有m个数量。又假设有k个进程。如果某进程要取得一些资源则系统首先测试是否满足资源请求要求,如果满足,则尝试分配,接着就判断分配后系统有没有发生死锁,有,就还原,没有就继续。如果某进程要求进入内存,则系统要判断所有进程的请求资源数有没有超过可用资源,有则不许建立,没有就可以建立该进程。
花了几个小时(其实大概一个小时就能搞定,不过可能困的原因,有两个错误没有看出来。我在此要提醒大家,编写程序的格式非常重要,不然检查错误是在很难。),终于写完程序和报告。下面就贴上我的代码吧。

/*
* 操作系统实验:
* 《银行家算法》本程序参考课本的例子,资源种数为3.如果要求更多可作相应更改。
*/

/**
*
* @author Kevin 华南农业大学
*/
//银行家算法,此为Banker类。
import java.util.ArrayList;
import java.util.Random;
public class Banker {
static int[] available = {10,5,7}; //各个资源可用的数量。
static ArrayList processM = new ArrayList(); //线性表,里面装的是进程。

public static void main(String[] args){ //主函数,调试用。
Process p1 = new Process(7,5,3);
Process p2 = new Process(3,2,2);
Process p3 = new Process(9,0,2);
Process p4 = new Process(2,2,2);
Process p5 = new Process(4,3,3);
processM.add(p1);
processM.add(p2);
processM.add(p3);
processM.add(p4);
processM.add(p5);

while(!p1.isOK() || !p2.isOK() || !p3.isOK() || !p4.isOK() || !p5.isOK()){ //进程都还有没满足的就继续申请。
p1 = (Process)processM.get(0);
p2 = (Process)processM.get(1);
p3 = (Process)processM.get(2);
p4 = (Process)processM.get(3);
p5 = (Process)processM.get(4);
if(!p1.isOK())
allocation(p1.request(),p1,0); //申请资源,以下同。
if(!p2.isOK())
allocation(p2.request(),p2,1);
if(!p3.isOK())
allocation(p3.request(),p3,2);
if(!p4.isOK())
allocation(p4.request(),p4,3);
if(!p5.isOK())
allocation(p5.request(),p5,4);

}

}

public static boolean allocation(int[] rq ,Process process,int n){ //进程请求分配函数,
if(process.have[0] + rq[0] > process.claim[0] || process.have[1] + rq[1] > process.claim[1] || process.have[2] + rq[2] > process.claim[2]){
System.out.println("申请失败。"+ (n+1)); //如果请求的资源比最大需求大,则申请失败。
return false;
}
else{
if(rq[0] > available[0] || rq[0] > available[0] || rq[0] > available[0]){
//如果要求的资源暂时不够,则先挂起。
}
else{
process.have[0] = process.have[0] + rq[0];
process.have[1] = process.have[1] + rq[1];
process.have[2] = process.have[2] + rq[2];
available[0] = available[0]-rq[0];
available[1] = available[1]-rq[1];
available[2] = available[2]-rq[2];
processM.add(n, process);
processM.remove(n+1);
}
if(safe()){ //如果安全,则分配成功。
System.out.println("申请成功。"+"进程"+ (n+1)+"已获得资源分别为:"+ process.have[0]+" "+process.have[1]+" "+process.have[2]);
return true;
//如果安全,那资源被该进程利用。
}
else{
process.have[0] = process.have[0] - rq[0];
process.have[1] = process.have[1] - rq[1];
process.have[2] = process.have[2] - rq[2];
available[0] = available[0]+ rq[0];
available[1] = available[1]+ rq[1];
available[2] = available[2]+ rq[2];
processM.add(n, process);
processM.remove(n+1);
System.out.println("申请失败。" + (n+1)); //不安全,则申请失败.
return false;
//如果不安全,则还原,并且挂起该进程。
}
}
}

public static boolean safe(){ //判断分配后是否安全。
ArrayList rest = new ArrayList(processM);
Process test ;
int num = rest.size();
int found = num*num;
while(found > 0 && !rest.isEmpty()){
test = (Process)rest.remove(0);
if(test.claim[0] - test.have[0] <= available[0] && test.claim[1] - test.have[1] <= available[1] && test.claim[2] - test.have[2] <= available[2] ){
available[0] = available[0] + test.have[0];
available[1] = available[1] + test.have[1];
available[2] = available[2] + test.have[2];

}
else {
rest.add(test);
}
found--;
}
if(rest.isEmpty()){
return true;
}
else
return false;
}
}

class Process{ //此类为进程类,描述的是一个进程。
int[] claim =new int[3]; //这个进程需要的资源数。
int[] have = new int[3];
public Process(int n1,int n2,int n3){ //初始化进程
claim[0] = n1;
claim[1] = n2;
claim[2] = n3;
have[0] = 0;
have[1] = 0;
have[2] = 0;
}
public boolean isOK(){ //判断这个进程得到满足没有。
if(have[0] == claim[0] && have[1] == claim[1] && have[2] == claim[2]){
return true;
}
else return false;
}
public int[] request(){ //这个函数随机生成3个数,作为某个进程的请求。
Random random = new Random(); //实例化随机对象。
int[] num = new int[3];
num[0] = random.nextInt(10);
System.out.println(num[0]);
num[1] = random.nextInt(10);
System.out.println(num[1]);
num[2] = random.nextInt(10);
System.out.println(num[2]);
return num;
}
}

热点内容
武汉大学学生会辅导员寄语 发布:2021-03-16 21:44:16 浏览:612
七年级学生作文辅导学案 发布:2021-03-16 21:42:09 浏览:1
不屑弟高考成绩 发布:2021-03-16 21:40:59 浏览:754
大学毕业证会有成绩单 发布:2021-03-16 21:40:07 浏览:756
2017信阳学院辅导员招聘名单 发布:2021-03-16 21:40:02 浏览:800
查询重庆2018中考成绩查询 发布:2021-03-16 21:39:58 浏览:21
结业考试成绩怎么查询 发布:2021-03-16 21:28:40 浏览:679
14中医医师资格笔试考试成绩查分 发布:2021-03-16 21:28:39 浏览:655
名著赏析课程标准 发布:2021-03-16 21:27:57 浏览:881
北京大学商业领袖高端培训课程 发布:2021-03-16 21:27:41 浏览:919