操作系統上機報告(2)_第1頁
操作系統上機報告(2)_第2頁
操作系統上機報告(2)_第3頁
操作系統上機報告(2)_第4頁
操作系統上機報告(2)_第5頁
免費預覽已結束,剩余7頁可下載查看

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、西安電子科技大學計算機學院操作系統實驗實驗報告級:more Iongtext 顯示出已經顯示出來的內容的百分比cat Iongtext I more 不顯示、題目實驗 1: LINUX/UNIX Shell 部分(一)系統基本命令1. 登陸系統,輸入whoami和pwd,確定自己的登錄名和當前目錄;登錄名admixx,當前目錄 /root/root2. 顯示自己的注冊目錄?命令在哪里? a.鍵入 echo $HOME,確認自己的主目錄;主目錄為b . 鍵入 echo $PATH , 記下自己看到的目錄表/usr/lib/qt-3.3/b in:/usr/kerberos/sb in:/usr/

2、kerberos/bin:/usr/local/sb in:/usr/local/b in:/sb in:/b in:/usr/sb in:/usr/b in:/usr/X11R6/b in:/root/b inC.鍵入 which abcd,看看得到的錯誤信息;/usr/b in/which:no abed in (/usr/lib/qt-3.3/bi n:/usr/kerberos/sb in:/usr/kerberos/bin:/usr/local/sb in:/usr/local/b in:/sb in:/b in:/usr/sb in:/usr/b in:/usr/X11R6/b i

3、n:/root/b in再鍵入 which ls和which vi,對比剛剛得到的結果的目錄是否在a.、b.兩題看到的目錄表中;alias ls= Is color=tty /bin/ls /bin/vi3. Is和cd的使用:a.鍵入Is, Is -I , Is -a , Is -al四條命令,觀察輸出,說明四種不同使用方式的區 另Is :列出目錄內容 Is -:以長格式詳細顯示文件信息Is力:列出所有文件,包括以.文件 Is Q :以長格式顯示當前目錄下的所有文件pwd確定位置,或鍵入 cd , cd -觀察效果.cd : 回至上戻目錄cd : 可進入用戶的 HOME 目錄b.利用cd轉到

4、/bin , /sbin , /etc , /dev,再利用ls列出各個目錄的內容, 如果 迷路”,可以利用cd , cd -的區別:(二)基本操作1 .用 cp 將 /usr/share下,然后進入自己的exercise目錄.2.輸入/輸出重定向和 cat, morea. 輸入b. 輸入c. 使用d. 輸入目錄下的exercise子目錄連同目錄下的文件拷貝到自己的主目錄等顯示命令的配合使用:Iongtext文件中的內容;longtext文件中的內容,是否發現一屏顯示不完?_cat命令列出目錄下cat命令列出目錄下more命令列出Iongtext的內容;cat hello.txt hello2

5、.txt,再輸入cat hello.txthello2.txt,再檢查 hello2.txt 的內容有何變化;說明 與 的區別。是把 hello.txt 的內容覆蓋在 hello2.txt 內 是把 hello.txt 的內容續寫在 hello2.txt內e. 對比兩條命令:more Iongtext和cat Iongtext | more,兩者有何不同點 ?f. 執行命令 echo hello.txt 文檔就會被清空g. 輸入命令 cat 符號 并可以輸入文檔h. 設計一條命令,使該命令可以從標準輸出中讀入;cat hello3.txt cat hello3.txt 就可以看至j(參考答案:

6、cat hello3.txt )3. 特殊字符:輸入 cat also a text.txt,看看能否打開目錄下的also a text.txt文件,若不能,該怎么辦? 輸入 cat“also a text.txt ”(參考答案:cat also a text.txt)4. 文件鏈接:a.用In命令為目錄下的Iongtext文件建立一個硬鏈接,鏈接名為Iongtext2 , 然后把Iongtext復制一個新文件 Iongtext3,用cat命令將 hello . txt的內容追加到Iongtext 的末尾,再用 diff命令比較Iongtext, Iongtext2和Iongtext3,看看有

7、什么結果,特別 是比較一下Iongtext和Iongtext2是否相同;Iongtext 禾口 Iongtext2 直是相同的 在 Iongtext 后續寫 hello.txt 之后,Iongtext 禾口 Iongtext2 均與 longtext3 不同了b.用In命令給Iongtext3建立一個符號鏈接Iongtext4,用 cat命令看看Iongtext4 ;然后刪去Iongtext3,再用cat命令看看Iongtext4,是否有什么不同?沒有不同c. 刪去Iongtext2,看看能否用catd. 試著執行 In -s ./abcde ./nulllink ,5.查找命令 find:用

8、find命令查找當前目錄下所有以 刪除前征求用戶許可.命令看到Iongtext?能看看是否能建立文件鏈接.不能del開頭或以del結尾的文件,并將其刪除,要求find ./ -n ame del*rm -del*6.文件的屬性:a. 用ls -l列出exercise目錄下所有的文件和目錄,觀察其權限位;b. 將hello2.txt的讀權限去掉,看看還能否用cat打開該文件;不能C.將Program目錄的讀權限去掉,看看是否能用ls命令看到其中內容?不能(三)Shell程序設計編寫一個Shell過程完成如下功能:1. 合并兩個$1、$2文件為$3,并顯示。2. 如果缺少$3,那么先報告缺少$3,

9、將合并后的內容輸出到CHENG.TXT顯示。3 .如果缺少$2、$3那么先報告缺少$2、$3,只顯示$1的內容。if test -f $3then cat $1 $2$3cat $3else if test -f $2then echo $3 is not a not in this directorycat $1 $2CHENGTXTcat CHENG.TXTelse echo Neither $2 or $3 is a in this directory cat $1fifi實驗2:實驗題目進程的建立實驗目的創建進程及子進程在父子進程間實現進程通信實驗軟硬件環境Linux、Windows9

10、8、Windows2000實驗內容創建進程并顯示標識等進程控制塊的屬性信息; 顯示父子進程的通信信息和相應的應答信息。(進程間通信機制任選)實驗步驟創建進程;顯示進程狀態信息; 實現父子進程通信;考核指標顯示創建的進程及控制塊參數; 顯示進程間關系參數源程序:#in clude#i nclude#in clude#in clude #in clude# defi ne BUFFERSIZE 32 int mai n()pid_t pid;int status;int fd2;char bufBUFFERSIZE=This is a pipen;if(pip e(fd)0)printfCpipe

11、 errorn);exit(1);p id=fork();if(p id0) prin tf(fork errotn);exit(1);if(pi d=0) prin tf(child pro cess:n); /child pro cess prin tf( pi d=%dn,get pid();prin tf( pp id=%dn,get pp id();prin tf(gid=%dn,getgid();prin tf(write:%sn,buf);close(fd0);/close writewrite(fd1,buf,sizeof(buf);/writeexit(1);else/par

12、enr p rocessif(p id!=wait(&status)prin tf(wait errorn);printfCparent p rocess:n);prin tf( pid=%dn,get pid();prin tf( pp id=%drTget pp id();prin tf(gid=%drr,getgid();實驗3:實驗題目進程間的同步實驗目的理解進程同步和互斥模型及其應用實驗軟硬件環境Linux、Windows98、Windows2000實驗內容利用通信API實現進程之間的同步: 建立司機和售票員進程; 并實現他們間的同步運行。實驗步驟創建進程;實現同步操作或函數;實現公

13、共汽車司機和售票員開關車門及行車運行過程 的同步模型;顯示同步運行的結果。考核指標顯示司機和售票員進程的冋步運行軌跡。司機進程代碼:#i nclude #i nclude #in clude vuni std.h#i nclude #i nclude #i nclude #in clude #i nclude #i nclude #in clude vfcn tl.h char SEM_NAME1= s1;char SEM_NAME2= s2;int main()int i;sem_t *s1;sem_t *s2;s1 = sem_o pen (SEM_NAME1, O_CREAT, 0644

14、, 0); if(s1 = SEM_FAILED)p error(u nable to create sema phore);sem_ un li nk(s1);exit(-1);s2 = sem_o pen (SEM_NAME2, O_CREAT, 0644, 0); if(s2 = SEM_FAILED)p error(u nable to create sema phore);sem_ un li nk(s2);exit(-1);for (i=0; i=2; i+) prin tf(driver reach stati on, stop carn); sem_ po st(s2);pri

15、n tf(driver wait ing closi ng door n); sem_wait(s1);prin tf(driver leavi ng statio nn);prin tf(car is runningn); slee p(2);sem_close(s1);sem_close(s2);sem_u nii nk(SEM_NAME1);sem_u nIi nk(SEM_NAME2); _exit(0);售票員進程代碼:#i nclude #i nclude #i nclude #i nclude vuni std.h#i nclude #i nclude #in clude #i

16、nclude #i nclude #in clude vfcn tl.h char SEM_NAME1= s1;char SEM_NAME2= s2;int main()int i;sem_t *s1;sem_t *s2;/create & in itialize sema phores1 = sem_o pen (SEM_NAME1,0, 0644, 0); if(s1 = SEM_FAILED)p error( un able to create sema phore); sem_close(s1);exit(-1);s2 = sem_o pen (SEM_NAME2, 0, 0644,

17、0); if(s2 = SEM_FAILED)p error( un able to create sema phore); sem_close(s2);exit(-1);for (i=0; i=2; i+) sem_wait(s2);prin tf(c on ductor open door, p asse nger, close door n); sem _po st(s1);prin tf(c on ductor wait ing reachi ng stati onn);sem_close(s1);sem_close(s2); _exit(0);運行結果:結果分析:利用PV操作實現司機

18、進程和售票員進程之間的同步。設司機進程的信 號量為S1,售票員進程信號量為S2。當車到站時,停車,進行操作 V(S2),P(S1)。 此時司機進程被掛起,售票員進程開始進行。售票員進程先進行P (S2)操作,若之前未進行V(S2)則被掛起,否則進程繼續執行,打開車門。待人上完后關車門,進 行V(S1)操作,喚醒被掛起的司機進程。汽車再次離站開出。實驗4:實驗題目LinUX文件系統實驗實驗目的通過熟悉使用相關命令、使用系統調用來讀寫文件 熟悉LinUX文件系統,并閱讀Linux文件系統設計與實現的相關資料,加深理解。實驗軟硬件環境Linux實驗內容文件命令文件操作的系統調用Linux文件系統理解

19、實驗步驟熟悉文件系統常用命令 (ls,mv,rm ,ln,cp ,co mp ress, uncomp ress,gz ip ,gu nzip ,rar,r pm,tar,df,m oun t,um oun t,chmod,chow n, );建立相關用戶和組,并熟悉文件系統的權限管理; 利用文件操作相關的系統調用實現一個文件拷貝命 令(參數為源文件、目標文件,提示源文件不存在, 提示目標文件存在是否覆蓋);閱讀Linux文件系統設計與實現的相關資料;考核指標演示實驗結果。#i nclude #i nclude #in clude vuni std.h#i nclude #i nclude #in clude vfen tl.h#defi ne BUFF_SIZE 1024int main (i nt argc, char *argv)int src_;int real_read_le n;un sig ned char buffBUFF_SIZE; char cover;/argc is not correct if(argc!=3) prin tf(Error use cop y!n); prin tf(Ex

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論