![操作系統(tǒng)進(jìn)程管理_第1頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/6/2bec2b08-e8a2-42f0-889c-ce060a27fa96/2bec2b08-e8a2-42f0-889c-ce060a27fa961.gif)
![操作系統(tǒng)進(jìn)程管理_第2頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/6/2bec2b08-e8a2-42f0-889c-ce060a27fa96/2bec2b08-e8a2-42f0-889c-ce060a27fa962.gif)
![操作系統(tǒng)進(jìn)程管理_第3頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/6/2bec2b08-e8a2-42f0-889c-ce060a27fa96/2bec2b08-e8a2-42f0-889c-ce060a27fa963.gif)
![操作系統(tǒng)進(jìn)程管理_第4頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/6/2bec2b08-e8a2-42f0-889c-ce060a27fa96/2bec2b08-e8a2-42f0-889c-ce060a27fa964.gif)
![操作系統(tǒng)進(jìn)程管理_第5頁](http://file3.renrendoc.com/fileroot_temp3/2021-12/6/2bec2b08-e8a2-42f0-889c-ce060a27fa96/2bec2b08-e8a2-42f0-889c-ce060a27fa965.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、計算機(jī)操作系統(tǒng)課程設(shè)計指導(dǎo)書河海大學(xué)2014年10月計算機(jī)操作系統(tǒng)課程設(shè)計說明計算機(jī)操作系統(tǒng)是計算機(jī)科學(xué)與技術(shù)專業(yè)的主要專業(yè)基礎(chǔ)課程,其實踐性、應(yīng)用性很強(qiáng)。實踐教學(xué)環(huán)節(jié)是必不可少的一個重要環(huán)節(jié)。計算機(jī)操作系統(tǒng)課程設(shè)計目的是加深對理論教學(xué)內(nèi)容的理解和掌握,使學(xué)生較系統(tǒng)地掌握操作系統(tǒng)的基本原理,加深對操作系統(tǒng)基本方法的理解,加深對課堂知識的理解,為學(xué)生綜合運(yùn)用所學(xué)知識,在Linux環(huán)境下編寫功能較簡單的程序來實現(xiàn)操作系統(tǒng)的基本方法、并在實踐應(yīng)用方面打下一定基礎(chǔ)。要求學(xué)生在指導(dǎo)教師的幫助下自行完成各個操作環(huán)節(jié),并能實現(xiàn)且達(dá)到舉一反三的目的,完成一個實驗解決一類問題。要求學(xué)生能夠全面、深入理解和熟練掌
2、握所學(xué)內(nèi)容,并能夠用其分析、設(shè)計和解答類似問題;對此能夠較好地理解和掌握,并且能夠進(jìn)行簡單分析和判斷;能夠熟練使用Linux用戶界面;掌握操作系統(tǒng)中進(jìn)程管理概念和控制方法;了解進(jìn)程的并發(fā),進(jìn)程之間的通信方式,了解虛擬存儲管理的基本思想,了解設(shè)備管理的功能,了解文件系統(tǒng)的功能。同時培養(yǎng)學(xué)生進(jìn)行分析問題、解決問題的能力;培養(yǎng)學(xué)生完成實驗分析、實驗方法、實驗操作與測試、實驗過程的觀察、理解和歸納能力。為了收到良好的實驗效果,編寫了這本課程設(shè)計指導(dǎo)書。在指導(dǎo)書中,每一個課程設(shè)計任務(wù)按照該課程設(shè)計大綱的要求編寫,力求緊扣理論知識點、突出設(shè)計方法、明確設(shè)計思路,通過多種形式引導(dǎo)學(xué)生有目的、有方向地完成課程
3、設(shè)計任務(wù),得出實驗結(jié)果。任課教師在課程設(shè)計前對課程設(shè)計的任務(wù)進(jìn)行一定的分析和講解,要求學(xué)生按照課程設(shè)計任務(wù)的具體要求提前做準(zhǔn)備工作,如:查找資料等,做到有準(zhǔn)備地上機(jī)。進(jìn)行課程設(shè)計時,指導(dǎo)教師應(yīng)檢查學(xué)生的預(yù)習(xí)情況,并對設(shè)計過程給予積極指導(dǎo)。課程設(shè)計完畢后,學(xué)生應(yīng)根據(jù)課程設(shè)計情況,實驗數(shù)據(jù)及結(jié)果,完成課程設(shè)計報告,由班長統(tǒng)一收齊后交指導(dǎo)教師審閱評定。任務(wù)1 進(jìn)程管理系統(tǒng)一、課程設(shè)計目的加深對進(jìn)程概念及進(jìn)程管理各部分內(nèi)容的理解;熟悉進(jìn)程管理中主要數(shù)據(jù)結(jié)構(gòu)的設(shè)計及進(jìn)程調(diào)度算法、進(jìn)程控制機(jī)構(gòu)、同步機(jī)構(gòu)及通訊機(jī)構(gòu)的實施。二、課程設(shè)計內(nèi)容設(shè)計一個允許n個進(jìn)程并發(fā)運(yùn)行的進(jìn)程管理模擬系統(tǒng)。該系統(tǒng)包括有簡單的進(jìn)程
4、控制、同步與通訊機(jī)構(gòu),其進(jìn)程調(diào)度算法可任意選擇(優(yōu)先級調(diào)度,時間片輪轉(zhuǎn),短進(jìn)程優(yōu)先中的一種)。每個進(jìn)程用一個PCB表示,其內(nèi)容根據(jù)具體情況設(shè)置。各進(jìn)程之間有一定的同步關(guān)系(可選)。系統(tǒng)在運(yùn)行過程中應(yīng)能顯示或打印各進(jìn)程的狀態(tài)及有關(guān)參數(shù)的變化情況,以便觀察諸進(jìn)程的運(yùn)行過程及系統(tǒng)的管理過程。任務(wù)5文件系統(tǒng)演示一、課程設(shè)計目的使學(xué)生熟悉文件管理系統(tǒng)的設(shè)計方法;加深對所學(xué)各種文件操作的了解及其操作方法的特點。二、課程設(shè)計內(nèi)容設(shè)計一個簡單的多用戶文件系統(tǒng)。即在系統(tǒng)中用一個文件來模擬一個磁盤;此系統(tǒng)至少有:Create、delete、open、close、read、write等和部分文件屬性的功能。實現(xiàn)這個
5、文件系統(tǒng)。 能實際演示這個文件系統(tǒng)?;旧鲜沁M(jìn)入一個界面(此界面就是該文件系統(tǒng)的界面)后,可以實現(xiàn)設(shè)計的操作要求。1進(jìn)程管理模擬系統(tǒng)。(1)問題描述本系統(tǒng)的同步機(jī)構(gòu)采用的信號量上的P、V操作的機(jī)制;控制機(jī)構(gòu)包括阻塞和喚醒操作;時間片中斷處理程序處理模擬的時間片中斷;進(jìn)程調(diào)度程序負(fù)責(zé)為各進(jìn)程分配處理機(jī)。系統(tǒng)中設(shè)計了3個并發(fā)進(jìn)程它們之間有如下同步關(guān)系:3個進(jìn)程需要互斥使用臨界資源s2,進(jìn)程1和進(jìn)程2又需互斥使用臨界資源s1。本系統(tǒng)在運(yùn)行過程中隨機(jī)打印出各進(jìn)程的狀態(tài)變換過程,系統(tǒng)的調(diào)度過程及公共交量的變化情況。(2)算法系統(tǒng)為進(jìn)程設(shè)置了5種運(yùn)行狀態(tài):e執(zhí)行態(tài);r高就緒態(tài);t低就緒態(tài)(執(zhí)行進(jìn)程因時間片
6、到限而轉(zhuǎn)入):w等待態(tài);c完成態(tài)。各進(jìn)程的初始狀態(tài)均設(shè)置為r。系統(tǒng)分時執(zhí)行各進(jìn)程。通過產(chǎn)生隨機(jī)數(shù)x來模擬時間片(每一個時間片并不相同)。當(dāng)進(jìn)程processl訪問隨機(jī)數(shù)x時,若x033;當(dāng)進(jìn)程proccss2訪問x時,若x<0.33或x0.66;當(dāng)進(jìn)程process3訪問x時,若x<0.66,則分別認(rèn)為各進(jìn)程的執(zhí)行時間片到限,產(chǎn)生“時間片中斷”面轉(zhuǎn)入低就緒態(tài)t。進(jìn)程調(diào)度算法采用剝奪式最高優(yōu)先數(shù)法。各進(jìn)程的優(yōu)先數(shù)通過鍵盤輸入予以靜態(tài)設(shè)置。調(diào)度程序每次總是選擇優(yōu)先數(shù)最小(優(yōu)先權(quán)最高)的就緒進(jìn)程投入執(zhí)行。先從r狀態(tài)進(jìn)程中選擇,再從t狀態(tài)進(jìn)程中選擇。當(dāng)現(xiàn)行進(jìn)程喚醒某個等待進(jìn)程,且被喚醒進(jìn)程
7、的比先數(shù)小于現(xiàn)行進(jìn)程時,則剝奪現(xiàn)行進(jìn)程的執(zhí)行權(quán)。各進(jìn)程在使用臨界資源s1和s2時,通過調(diào)用信號量sem1和sem2上的P、V操作來實現(xiàn)同步。阻塞和喚醒操作負(fù)責(zé)完成從進(jìn)程的執(zhí)行態(tài)到等待態(tài)以及從就緒態(tài)的轉(zhuǎn)變。系統(tǒng)啟動后,在完成必要的系統(tǒng)初始化后便執(zhí)行進(jìn)程調(diào)度程序。當(dāng)執(zhí)行因“時間片中斷”,或者被排斥使用臨界資源,或喚醒某個等待進(jìn)程時,立即進(jìn)行進(jìn)程調(diào)度。當(dāng)3個進(jìn)程都處于完成狀態(tài)后,系統(tǒng)退出運(yùn)行。(3)數(shù)據(jù)結(jié)構(gòu)每個進(jìn)程一個PCB,內(nèi)容:id進(jìn)程標(biāo)識status 進(jìn)程狀態(tài)priority進(jìn)程優(yōu)先數(shù)nextwr等待隊鏈指針,指示在同一信號量上等待的下一個進(jìn)程的標(biāo)識。信號量。對應(yīng)于臨界資源s1和s2分別有se
8、m1和sem2,均為互斥號量,內(nèi)容包括:value信號量值,初值為1firstwr等待鏈指針,指示在該信號量上第一個等待進(jìn)程的標(biāo)識數(shù)。保留區(qū)。用數(shù)組saveaera34表示。即每個進(jìn)程都有一個大小為4個單元的保留區(qū),用來保存被“中斷”時的現(xiàn)場信息,如通用寄存器的內(nèi)容和斷點地址等。全程變量。exe執(zhí)行進(jìn)程指針,其值為進(jìn)程標(biāo)識數(shù)i用來模擬一個通用寄存器。(4)用TurboC編寫的程序代碼:#include <stdlib.h>#include <time.h>#include <stdio.h>#define TRUE 1#define FALSE 0#defi
9、ne MAXPRI 100#define NIL -1struct int id; char status; int nextwr; /*等待鏈指針,指示在同一信號量上等待的下一個進(jìn)行進(jìn)程的標(biāo)識符* int priority; pcb3;struct int value; int firstwr; /*等待鏈?zhǔn)字羔?,指示該信號量上第一個等待進(jìn)程的標(biāo)識數(shù)*/ sem2;char savearea34,addr;int i,s1=0,s2=0,seed,exe=NIL;init( ) int j; for(j=0;j<3;j+) pcbj.id=j; pcbj.status='r
10、39; pcbj.nextwr=NIL; printf("nprocess%dpriority?",j+1); scanf("%d",&i); pcbj.priority=i; sem0.value=1; sem0.firstwr=NIL; sem1.value=1; sem1.firstwr=NIL; for(i=0;i<3;i+) for(j=0;j<4;j+) saveareaij='0'float random()float m;srand(time(0);m=(1+rand()%3)%3-0.1; print
11、f("random m=%fn",m); getchar();return(m);timeint(ad) /*time slice interupt*/char ad; float x; x=random(); if(x<0.33)&&(exe=0)return(FALSE); if(x<0.66)&&(exe=1)return(FALSE); if(x<1.0)&&(exe=2)return(FALSE);saveareaexe0=i;saveareaexe1=ad;pcbexe.status='t
12、'printf("This times slice interrupt process%d enter into readyn",exe+1);exe=NIL;return(TRUE);scheduler( ) int pd; if(pd=find()=NIL&&exe=NIL) return(NIL); /*quit system*/ if(pd!=NIL) if(exe=NIL) pcbpd.status='e' exe=pd; printf("proccess%d is executingn",exe+1);
13、 else if(pcbpd.priority<pcbexe.priority) pcbexe.status='r' printf("process%d enter into readyn",exe+1); pcbpd.status='e' exe=pd; printf("process%d is executingn", exe+1); i=saveareaexe0; addr=saveareaexe1; return(exe); find( ) int j,pd=NIL,w=MAXPRI; for(j=0;j&l
14、t;3;j+) if(pcbj.status='r') if(pcbj.priority<w) w=pcbj.priority; pd=j; if (pd=NIL) for(j=0;j<3;j+) if(pcbj.status='t') if(pcbj.priority<w) w=pcbj.priority; pd=j; return(pd); p(se,ad)int se;char ad; if(-semse.value>=0) return(FALSE); block(se); saveareaexe0=i; saveareaexe1
15、=ad; exe=NIL; return(TRUE); block(se)int se; int w; printf("process%d is blockedn",exe+1); pcbexe.status='w' pcbexe.nextwr=NIL; if(w=semse.firstwr)=NIL) semse.firstwr=exe; else while(pcbw.nextwr!=NIL) w=pcbw.nextwr; pcbw.nextwr=exe; v(se,ad)int se;char ad;if(+semse.value>0) retu
16、rn(FALSE); wakeup(se); saveareaexe1=ad; saveareaexe0=i; return(TRUE); wakeup(se)int se; int w; w=semse.firstwr; if(w!=NIL) semse.firstwr=pcbw.nextwr; pcbw.status='r' printf("process%d is waken upn",w+1); process1() if(addr='a') goto a1; if(addr='b') goto b1; if(addr
17、='c') goto c1; if(addr='d') goto d1; if(addr='e') goto e1; if(addr='f') goto f1; for(i=0; i<3;i+)/*如果程序執(zhí)行超過次,則*/ printf("process1 calls P on the semaphore 1n"); if(p(0,'a') break; /*process 1 is blocked*/a1: printf("process1 is executing in t
18、he cretical section 1n"); if(timeint('b') break; /*time silce interrupt*/b1: printf("s1=%dn",+s1); printf("process1 calls V on semaphorel and quit cretical section 1.n"); if(v(0,'c') break; /*wake up a blocked process*/c1: printf("process1 calls P on sem
19、aphorel 2.n"); if(p(1,'d') break;d1: printf("process1 is execting cretical section 2.n"); if(timeint('e') break;e1: printf("s2=%dn",+s2); printf("process1 calls V on semaphore2 and quit cretical section2.n"); if(v(1,'f') break; /*wake up a b
20、lock process*/f1: printf("process1 cycle count=%dn",i); if(i<3) return; eexit(0); process2() if(addr='a') goto a2; if(addr='b') goto b2; if(addr='c') goto c2; if(addr='d') goto d2; if(addr='e') goto e2; if(addr='f') goto f2; for(i=1;i<6
21、;+i) printf("process2 call P on semaphore2n"); if(p(1,'a') break; /*process2 is blocked*/a2: printf("process2 is executing on the cretical setion2n"); if(timeint('b') break;b2: printf("s2=%dn",+s2); printf("process2 is calls V on semaphore2 and quit
22、 cretical section2.n"); if(v(1,'c') break; /*wake up a blocked process*/c2: printf("process2 call P on semphore 1.n"); if(p(0,'d') break; /*process2 is blocked*/d2: printf("process2 is executing cretical setion1n"); if(timeint('e') break;e2: printf(&q
23、uot;s1=%dn",+s1); printf("process2 call V on semaphorel and quit cretical setion2n"); if(v(0,'f') break; /*wkup up a block process*/f2: printf("process2 cycle count=%dn",i); if(i<6) return; eexit(1); process3()if(addr='a') goto a3;if(addr='b') goto
24、 b3;if(addr='c') goto c3;for(i=1;i<6;+i) printf("process3 call P on semaphore2n"); if(p(1,'a') break; /*process3 is blocked*/a3: printf("process3 is executing on its cretical section.n"); if(timeint('b') break;b3: printf("s2=%dn",+s2); printf(
25、"process3 calls V on semaphore and quit cretical section.n"); if(v(1,'c') break; /*wake up a blocked process */c3: printf("process3 cyclen count=%dn",i); if(i<6) return; eexit(2);eexit(n)int n; pcbn.status='c' printf("process%d is completed!n",n+1); e
26、xe=NIL;main() int j=0; int k; char m; printf("* * * * process management * * * *nn"); init(); printf("s1=%d, s2=%dn",s1,s2); printf("process1,process2,process3 are all in ready!n"); for(;) j=j+1; printf("n%dth Scheduler Press ENTER to continuen",j); /scanf(&qu
27、ot;%s",&m); getchar(); if(k=scheduler()!=NIL) switch(k) case 0: process1(); break; case 1: process2(); break; case 2: process3(); break; default: printf("process identifer errorn"); break; else break; printf("s1=%d, s2=%dn",s1,s2); printf("n* * * * END * * * *n"
28、;); 2文件系統(tǒng)參考程序見下(本程序需要在c:下建一個名為osfile的目錄及一個名為file的子目錄):#include "stdio.h"#include "string.h"#include "conio.h"#include "stdlib.h"#define MAXNAME 25 /*the largest length of mfdname,ufdname,filename*/#define MAXCHILD 50 /*the largest child*/#define MAX (MAXCHILD*
29、MAXCHILD) /*the size of fpaddrno*/typedef struct /*the structure of OSFILE*/ int fpaddr; /*file physical address*/ int flength; /*file length*/ int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write(default);*/ char fnameMAXNAME; /*file name*/ OSFILE;typedef struct /*the structure of OSUFD
30、*/ char ufdnameMAXNAME; /*ufd name*/ OSFILE ufdfileMAXCHILD; /*ufd own file*/ OSUFD;typedef struct /*the structure of OSUFD'LOGIN*/ char ufdnameMAXNAME; /*ufd name*/ char ufdpword8; /*ufd password*/ OSUFD_LOGIN;typedef struct /*file open mode*/ int ifopen; /*ifopen:0-close,1-open*/ int openmode;
31、 /*0-read only,1-write only,2-read and write,3-initial*/ OSUFD_OPENMODE;OSUFD *ufdMAXCHILD; /*ufd and ufd own files*/OSUFD_LOGIN ufd_lp;int ucount=0; /*the count of mfd's ufds*/int fcountMAXCHILD; /*the count of ufd's files*/int loginsuc=0; /*whether login successfully*/char usernameMAXNAME;
32、 /*record login user's name22*/char dirnameMAXNAME;/*record current directory*/int fpaddrnoMAX; /*record file physical address num*/OSUFD_OPENMODE ifopenMAXCHILDMAXCHILD; /*record file open/close*/int wgetchar; /*whether getchar()*/FILE *fp_mfd,*fp_ufd,*fp_file_p,*fp_file;void main()int i,j,choi
33、ce1; char choice50; /*choice operation:dir,create,delete,open,delete,modify,read,write*/ int choiceend=1; /*whether choice end*/ char *rtrim(char *str); /*remove the trailing blanks.*/ char *ltrim(char *str); /*remove the heading blanks.*/ void LoginF(); /*LOGIN FileSystem*/ void DirF(); /*Dir FileS
34、ystem*/ void CdF(); /*Change Dir*/ void CreateF(); /*Create File*/ void DeleteF(); /*Delete File*/ void ModifyFM(); /*Modify FileMode*/ void OpenF(); /*Open File*/ void CloseF(); /*Close File*/ void ReadF(); /*Read File*/ void WriteF(); /*Write File*/ void QuitF(); /*Quit FileSystem*/ void help(); i
35、f(fp_mfd=fopen("c:osfilemfd","rb")=NULL) fp_mfd=fopen("c:osfilemfd","wb");fclose(fp_mfd); for(i=0;i<MAX;i+) fpaddrnoi=0; textattr(BLACK*16|WHITE); clrscr(); /*clear screen*/ LoginF(); /*user login*/ clrscr(); if(loginsuc=1) /*Login Successfully*/ while (1)
36、wgetchar=0; if (choiceend=1) printf("nnC:%s>",strupr(dirname); else printf("Bad command or file name.nC:%s>",strupr(username); gets(choice); strcpy(choice,ltrim(rtrim(strlwr(choice); if (strcmp(choice,"dir")=0) choice1=1; else if(strcmp(choice,"creat")=0
37、) choice1=2; else if(strcmp(choice,"delete")=0) choice1=3; else if(strcmp(choice,"attrib")=0) choice1=4; else if(strcmp(choice,"open")=0) choice1=5; else if(strcmp(choice,"close")=0) choice1=6; else if(strcmp(choice,"read")=0) choice1=7; else if(strc
38、mp(choice,"modify")=0) choice1=8; else if(strcmp(choice,"exit")=0) choice1=9; else if(strcmp(choice,"cls")=0) choice1=10; else if(strcmp(choice,"cd")=0) choice1=11; else if(strcmp(choice,"help")=0) choice1=20; else choice1=12; switch(choice1) case 1:
39、DirF();choiceend=1;break;case 2:CreateF();choiceend=1;if(!wgetchar) getchar();break;case 3:DeleteF();choiceend=1;if(!wgetchar)getchar();break;case 4:ModifyFM();choiceend=1;if(!wgetchar) getchar();break;case 5:choiceend=1;OpenF();if (!wgetchar) getchar();break;case 6:choiceend=1;CloseF();if (!wgetcha
40、r) getchar();break;case 7:choiceend=1;ReadF();if (!wgetchar) getchar();break;case 8:choiceend=1;WriteF();if (!wgetchar) getchar();break;case 9:printf("nYou have exited this system."); QuitF();exit(0);break;case 10:choiceend=1;clrscr();break;case 11:CdF();choiceend=1;break;case 20:help();ch
41、oiceend=1;break;default:choiceend=0; else printf("nAccess denied.");void help(void)printf("nThe Command Listn");printf("nCd Attrib Creat Modify Read Open Cls Delete Exit Closen");char *rtrim(char *str) /*remove the trailing blanks.*/int n=strlen(str)-1; while(n>=0) i
42、f(*(str+n)!=' ') *(str+n+1)='0'break; else n-; if (n<0) str0='0' return str;char *ltrim(char *str) /*remove the heading blanks.*/char *rtrim(char *str); strrev(str); rtrim(str); strrev(str); return str;void LoginF() /*LOGIN FileSystem*/char loginameMAXNAME,loginpw9,logincp
43、w9,str50; int i,j,flag=1; char a25; int findout; /*login user not exist*/ char *rtrim(char *str); /*remove the trailing blanks.*/ char *ltrim(char *str); /*remove the heading blanks.*/ void InputPW(char *password); /*input password,use '*' replace*/ void SetPANo(int RorW); /*Set physical add
44、ress num*/ while(1) findout=0; printf("nnLogin Name:"); gets(loginame); ltrim(rtrim(loginame); fp_mfd=fopen("c:osfile","rb"); for(i=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;i+) if (strcmp(strupr(ufd_lp.ufdname),strupr(loginame)=0)findout=1; strcpy(logincpw,u
45、fd_lp.ufdpword); fclose(fp_mfd); if (findout=1) /*user exist*/printf("Login Password:"); InputPW(loginpw); /*input password,use '*' replace*/ if (strcmp(loginpw,logincpw)=0) strcpy(username,strupr(loginame); strcpy(dirname,username); fp_mfd=fopen("c:osfile","rb"
46、); for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j+)strcpy(str,"c:osfile"); strcat(str,ufd_lp.ufdname); ufdj=(OSUFD*)malloc(sizeof(OSUFD); strcpy(ufdj->ufdname,strupr(ufd_lp.ufdname); fp_ufd=fopen(str,"rb"); fcountj=0; for(i=0;fread(&ufdj->ufdfilei,sizeof(O
47、SFILE),1,fp_ufd)!=0;i+,fcountj+) ifopenji.ifopen=0; ifopenji.openmode=4; fclose(fp_ufd); fclose(fp_mfd); ucount=j; SetPANo(0); printf("nnLogin successful! Welcome to this FileSystemnn"); loginsuc=1; return; else printf("nn"); flag=1; while(flag) printf("Login Failed! Passwor
48、d Error. Try Again(Y/N):"); gets(a); ltrim(rtrim(a); if (strcmp(strupr(a),"Y")=0) loginsuc=0;flag=0; else if(strcmp(strupr(a),"N")=0)loginsuc=0;flag=0;return; else printf("New Password(<=8):"); InputPW(loginpw); /*input new password,use '*' replace*/ pri
49、ntf("nConfirm Password(<=8):"); /*input new password,use '*' replace*/ InputPW(logincpw); if (strcmp(loginpw,logincpw)=0) strcpy(ufd_lp.ufdname,strupr(loginame); strcpy(ufd_lp.ufdpword,loginpw); fp_mfd=fopen("c:osfile","ab"); fwrite(&ufd_lp,sizeof(OSUFD_L
50、OGIN),1,fp_mfd); fclose(fp_mfd); strcpy(username,strupr(loginame); strcpy(dirname,loginame); strcpy(str,"c:osfile"); strcat(str,username); if(fp_ufd=fopen(str,"rb")=NULL)fp_ufd=fopen(str,"wb"); fclose(fp_ufd); fp_mfd=fopen("c:osfile","rb"); for(j=0;f
51、read(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j+)strcpy(str,"c:osfile"); strcat(str,ufd_lp.ufdname); ufdj=(OSUFD*)malloc(sizeof(OSUFD); strcpy(ufdj->ufdname,strupr(ufd_lp.ufdname); fp_ufd=fopen(str,"rb"); for(i=0;fread(&ufdj->ufdfilei,sizeof(OSFILE),1,fp_ufd)!=0;i+,
52、fcountj+) ifopenji.ifopen=0; ifopenji.openmode=4; fclose(fp_ufd); fclose(fp_mfd); ucount=j; SetPANo(0); printf("nnLogin Successful! Welcome to this Systemnn"); loginsuc=1; return; else printf("nn"); flag=1; while(flag) printf("Login Failed! Password Error. Try Again(Y/N):&qu
53、ot;); gets(a); ltrim(rtrim(a); if (strcmp(strupr(a),"Y")=0) loginsuc=0;flag=0; else if(strcmp(strupr(a),"N")=0)loginsuc=0;flag=0;return; void SetPANo(int RorW) /*Set physical address num,0-read,1-write*/int i,j; if (RorW=0)if(fp_file_p=fopen("c:osfilefilefile_p","r
54、b")=NULL) fp_file_p=fopen("c:osfilefilefile_p","wb"); fclose(fp_file_p); fp_file_p=fopen("c:osfilefilefile_p","rb"); for(i=0;fread(&j,sizeof(int),1,fp_file_p)!=0;i+) fpaddrnoj=1; /*for(i=1;i<MAX;i+) if (i%13)=0) fpaddrnoi=1;*/ elsefp_file_p=fopen(&
55、quot;c:osfilefilefile_p","wb"); /*for(i=1;i<MAX;i+) if(i%13)=0) fpaddrnoi=0;*/ for(i=0;i<MAX;i+) if (fpaddrnoi=1)fwrite(&i,sizeof(int),1,fp_file_p); fclose(fp_file_p);void InputPW(char *password) /*input password,use '*' replace*/int j; for(j=0;j<=7;j+)passwordj=g
56、etch(); if (int)(passwordj)!=13) if(int)(passwordj)!=8) putchar('*');else if (j>0)j-;j-; putchar('b');putchar(' ');putchar('b');else j-; else passwordj='0' break; passwordj='0'void DirF() /*Dir FileSystem*/int i,j,count=0; char sfmode25,sfpaddr25,str25; int ExistD(char *dirname); /*Whether DirName Exist,Exist-i,Not Exist-0*/ clrscr(); if (strcmp(strupr(ltrim(rtrim(dirname),"")!=0) pr
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 語文-河南金太陽2024-2025學(xué)年高二上學(xué)期第二次月考
- 2025年比特幣投資項目建議書
- 2025年吡唑啉酮項目合作計劃書
- 2025年濕式碾米機(jī)項目建議書
- 加強(qiáng)云服務(wù)與本地數(shù)據(jù)同步策略
- 智能科技服務(wù)合同
- 設(shè)備采購申請說明及預(yù)算分析報告書
- 雷鋒的敬業(yè)精神觀后感
- 智聯(lián)保密協(xié)議
- 8-Iodooctan-1-amine-生命科學(xué)試劑-MCE
- 公路工程節(jié)后復(fù)工安全教育
- 2024.8.1十七個崗位安全操作規(guī)程手冊(值得借鑒)
- 小王子-英文原版
- T-CHTS 10021-2020 在役公路隧道長期監(jiān)測技術(shù)指南
- 醫(yī)院門診醫(yī)生績效考核標(biāo)準(zhǔn)及評分細(xì)則
- 醫(yī)院納入定點后使用醫(yī)療保障基金的預(yù)測性分析報告
- 北師大版六年級下冊書法練習(xí)指導(dǎo)教案教學(xué)設(shè)計
- 《企業(yè)經(jīng)營統(tǒng)計學(xué)》課程教學(xué)大綱
- 如何做好健康沙龍
- 交通安全設(shè)施養(yǎng)護(hù)技術(shù).ppt
- 環(huán)錘式碎煤機(jī)使用說明書(參考)
評論
0/150
提交評論