


版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精品文檔中南高校linux 系統(tǒng)試驗(yàn)報(bào)告9歡。迎下載目 錄試驗(yàn)一39試驗(yàn)二1016試驗(yàn)三1717試驗(yàn)一 shell 程序設(shè)計(jì) 試驗(yàn)?zāi)康?理解 shell 程序的設(shè)計(jì)方法;生疏shell 程序的編輯、運(yùn)行、調(diào)試方法與過(guò)程。 試驗(yàn)內(nèi)容 考勤模擬shell 程序設(shè)計(jì)用 shell 設(shè)計(jì)一個(gè)考勤模擬程序,實(shí)現(xiàn)如下功能選擇界面: 1.上班簽到2. 下班簽出3. 缺勤信息查閱4. 退出考勤程序運(yùn)行后,提示用戶輸入上述功能選擇,并驗(yàn)證用戶輸入的用戶名和密碼;用戶信息保存在userinfo.dat 中。假如是上班簽到,記錄簽到信息,假如簽到時(shí)間大于上午8 時(shí),則提示用戶遲到,并記錄該遲到信息到check.da
2、t。假如是下班簽出,記錄簽出信息,假如簽出時(shí)間小于下午6 時(shí),則提示用戶早退,并記錄該早退信息到check.dat。假如用戶選擇缺勤信息查詢,則將 check.dat 中對(duì)應(yīng)當(dāng)用戶的遲到早退信息查出并顯示。用戶選擇功能執(zhí)行完,shell 程序連續(xù)回到功能選擇界面等待下一個(gè)用戶進(jìn)行操作。一、試驗(yàn)分析本試驗(yàn)是shell 程序設(shè)計(jì),主要目的是理解 shell 程序的設(shè)計(jì)方法以及生疏shell 程序的編輯、運(yùn)行、調(diào)試方法與過(guò)程。shell 是系統(tǒng)的用戶界面,供應(yīng)了用戶與內(nèi)核進(jìn)行交互操作的一種接口。它接收用戶輸入的命令并把它送入內(nèi)核去執(zhí)行。實(shí)際上 shell 是一個(gè)命令解釋器,它解釋由用戶輸入的命令并且
3、把它們送到內(nèi)核。不僅如此,shell 有自己的編程語(yǔ)言用于對(duì)命令的編輯,它允許用戶編寫(xiě)由shell 命令組成的程序。shell 編程語(yǔ)言具有一般編程語(yǔ)言的很多特點(diǎn),比如它也有循環(huán)結(jié)構(gòu)和分支把握結(jié)構(gòu)等,用這種編程語(yǔ)言編寫(xiě)的 shell 程序與其他應(yīng)用程序具有同樣的效果。本試驗(yàn)要求設(shè)計(jì)一個(gè)考情模擬的shell 程序,依據(jù)題目要求,可將整個(gè)程序分為五個(gè)部分:main 函數(shù)以及四個(gè)功能函數(shù),及一個(gè)功能對(duì)應(yīng)一個(gè)函數(shù)。1、上下班簽到將此函數(shù)定義為 check_in();依據(jù)題目要求,運(yùn)行程序后首先要求用戶輸入用戶名和密碼,當(dāng)用戶名密碼正確時(shí)才可進(jìn)入,這就要用到shell 編程中的變量,shell 中的變量
4、和c 語(yǔ)言或是 java 中的變量都有所不同,shell 中的變量不需要事先聲明,給一個(gè)變量賦值實(shí)際上就定義了一個(gè)變量,并且shell 程序中的變量是無(wú)類型的。read name password;我們定義兩個(gè)變量name 和 password,由題目要求,用戶名和密碼需要由用戶輸入,因此我們定義的變量應(yīng)當(dāng)從鍵盤(pán)獵取輸入值,使用如下語(yǔ)句:我們?cè)陂_(kāi)發(fā)程序前應(yīng)先創(chuàng)建一個(gè)文件userinfo.dat 用于存放用戶的用戶名和密碼,當(dāng)用戶輸入用戶名和密碼后就要推斷該用戶是否合法。方法為從userinfo.dat 文件中逐行讀取數(shù)據(jù),并推斷是否與用戶輸入的用戶名相同,當(dāng)遇到相同的用戶名時(shí)就表明該用戶是合法
5、的,可以退出文件的讀取,轉(zhuǎn)入推斷該用戶輸入的密碼是否正確。從文件中逐行讀取數(shù)據(jù)方法:if test -e /home/poe/userinfo.dat thenwhile read u_name u_password doif test “$name“ = “$u_name“ thenbreak; elsecontinue;fidone < /home/poe/userinfo.dat用戶名和密碼正確后用戶進(jìn)入系統(tǒng),系統(tǒng)顯示用戶簽到成功,此時(shí)還要推斷此時(shí)的時(shí)間是否大于上午 8 時(shí),則提示用戶遲到,并記錄該遲到信息到check.dat。2、下班簽出將此函數(shù)定義為check_out() ,前
6、面部分和上一個(gè)函數(shù)check_in()相同,都為推斷用戶輸入的用戶名和密碼。不同之處在于記錄簽出信息,假如簽出時(shí)間小于下午 6 時(shí),則提示用戶早退,并記錄該早退信息到check.dat。3、缺勤信息查閱將此函數(shù)定義為 look(),首先還是推斷該用戶輸入的用戶名和密碼是否正確。用戶進(jìn)入系統(tǒng)之后就要打印出該用戶的簽到信息,將 check.dat 中對(duì)應(yīng)當(dāng)用戶的遲到早退信息查出并顯示。在這一步中,首先還是要從 check.dat 文件中逐行讀取數(shù)據(jù),不過(guò)并不直接打印,而是要等推斷用戶名后才能打印。while read recorddouser=$record% *;if test “$user“
7、= “$name“ thenecho “$record“;fidone < /home/poe/check.dat其中 user=$record% *;語(yǔ)句表示截取 record 字符串從左邊起第一個(gè)空格前的字符串,也就是用戶名,然后檢查和該用戶的用戶名是否匹配,若匹配則打印否則讀取下一條。二、試驗(yàn)源碼#! /bin/bashfunction show()echo “-welcome to attandance system“;echo “-1.check in“;echo “-2.check out“;echo “-3.late“;echo “-4.exit“;echo “please
8、 input your choice:“;function check_in()echo “please input your name and password:“; read name password;if test -e /home/poe/userinfo.dat thenwhile read u_name u_password doif test “$name“ = “$u_name“ thenbreak; elsecontinue;fidone < /home/poe/userinfo.dat if test “$name“ != “$u_name“thenecho “so
9、rry,your name is wrong!“; elif test “$password“ != “$u_password“ thenecho “sorry,your password is wrong!“; elseecho “congratulation! you are checked in at date“; if test date +%h -gt 8thenecho “you are late!“;echo “$name checked in at “+date+“.late!“>> check.dat;fifi elseecho “there is no this
10、 file“;fifunction check_out()echo “please input your name and password:“; read name password;if test -e /home/poe/userinfo.dat thenwhile read u_name u_password doif test “$name“ = “$u_name“ thenbreak; elsecontinue;fidone < /home/poe/userinfo.dat if test “$name“ != “$u_name“ thenecho “sorry,your n
11、ame is wrong!“; elif test “$password“ != “$u_password“ thenecho “sorry,your password is wrong!“; elseecho “congratulation! you are checked out at “+date; if test date +%h -lt 18thenecho “you are early to leave!“;fi elseecho “$name checked out at “+date+“.early!“>>check.dat;fiecho “there is no
12、this file“;fifunction look()echo “please input your name and password:“; read name password;if test -e /home/poe/userinfo.dat thenwhile read u_name u_password doif test “$name“ = “$u_name“ thenbreak; elsecontinue;fidone < /home/poe/userinfo.dat if test “$name“ != “$u_name“ thenecho “sorry,your na
13、me is wrong!“; elif test “$password“ != “$u_password“ thenecho “sorry,your password is wrong!“; elsewhile read record douser=$record% *;if test “$user“ = “$name“ thenecho “$record“;fidone < /home/poe/check.datfi elseecho “there is no this file“;fifunction main()clear; show;read choice; case $choi
14、ce in1) check_in;2) check_out;3) look;4) exit;*) echo “please input 14“; esacmain;三、試驗(yàn)步驟及截圖進(jìn)入終端,輸入./attand.sh精品文檔18歡。 迎下載試驗(yàn) 2 linux 高級(jí)程序設(shè)計(jì)-進(jìn)程通信1、試驗(yàn)?zāi)康?1)了解 linux 操作系統(tǒng)下應(yīng)用程序開(kāi)發(fā)流程(2)把握 gnu 工具鏈的使用(3)了解 linux 高級(jí)編程技巧(例如 ipc 機(jī)制、系統(tǒng)調(diào)用等)2、試驗(yàn)內(nèi)容(1) 編寫(xiě)一個(gè)簡(jiǎn)潔的 c 語(yǔ)言程序,編寫(xiě)makefile 文件。了解編譯過(guò)程,并用 gdb 進(jìn)行調(diào)試。(2) 以下任選其一:1. 編寫(xiě)一
15、個(gè)多進(jìn)程通信程序,接受 message queue 或 shared memory 或者pipeline file 機(jī)制進(jìn)行通信2. 編寫(xiě)一個(gè)實(shí)現(xiàn)讀者-寫(xiě)者問(wèn)題的程序,用信號(hào)量機(jī)制備注:讀者-寫(xiě)者問(wèn)題設(shè)有一組共享數(shù)據(jù) db 和兩組并發(fā)進(jìn)程,一組進(jìn)程只對(duì)此組數(shù)據(jù)執(zhí)行讀操作, 另一組進(jìn)程可對(duì)此組數(shù)據(jù)執(zhí)行寫(xiě)操作(同時(shí)也可以執(zhí)行讀操作)。將前面一組進(jìn)程稱為讀者,后一組進(jìn)程稱為寫(xiě)者。為了保證共享數(shù)據(jù)的完整性,要求:(1) 多個(gè)讀者的操作可以同時(shí)進(jìn)行(2) 多個(gè)寫(xiě)者的操作不行同時(shí)進(jìn)行(3) 任何讀者與寫(xiě)者的操作不行同時(shí)進(jìn)行3、試驗(yàn)要求(1) 寫(xiě)出源程序,并編譯運(yùn)行(2) 具體記錄程序調(diào)試及運(yùn)行結(jié)果一、ma
16、kefile 思路分析在本試驗(yàn)中編寫(xiě)輸入同學(xué)人數(shù)及分?jǐn)?shù),計(jì)算同學(xué)的總成果以及平均成果的程序,源程序如下:#include <stdio.h>#include “chengji.h“ int main()int n,i;float sum,avg;printf(“please input the number ofstudents:“); scanf(“%d“,&n);float scoren; for(i=0;i<n;i+)printf(“please input the score of student%d“,i); scanf(“%d“,&scorei);
17、sum=fun_sum(score,n); avg=fun_avg(score,n);printf(“the sum is %f,the avg is %f“,sum,avg);/*main.c*/float fun_sum(float array,int n);float fun_avg(float array,int n);/*chengji.h*/float fun_sum(float array,int n) float sum=0.0;for(int i=0;i<n;i+) sum+=arrayi;return sum;/*fun_sum.c*/float fun_avg(fl
18、oat array,int n) float avg=0.0;for(int i=0;i<n;i+) avg+=arrayi;avg/=n; return avg;/*fun_avg.c*/makefile 文件如下:main:main.o fun_sum.o fun_avg.ogcc main.o fun_sum.o fun_avg.o -o main main.o:main.c chengji.hgcc main.c -c fun_sum.o:fun_sum.cgcc fun_sum.c -c fun_avg.o:fun_avg.c gcc fun_avg.c -c運(yùn)行結(jié)果如下:二、
19、讀者-寫(xiě)者思路分析讀寫(xiě)信號(hào)量的特點(diǎn)是:1. 同一時(shí)刻最多有一個(gè)寫(xiě)者(writer)獲得鎖;2. 同一時(shí)刻可以有多個(gè)讀者(reader)獲得鎖;3. 同一時(shí)刻寫(xiě)者和讀者不能同時(shí)獲得鎖;#include <pthread.h>#include <stdio.h> #include <unistd.h>/ 定義數(shù)據(jù)類class datapublic:data(int i, float f): i(i), f(f)int i;float f;/ 讀者寫(xiě)者讀寫(xiě)的內(nèi)容data *p_data = null;pthread_rwlock_t lock;/ 寫(xiě)者數(shù)目cons
20、t int writer_number = 2;void *reader(void *arg);void *writer(void *arg);int main(int argc, char *argv)pthread_t reader_tid;pthread_t writer_tidwriter_number;pthread_create(&reader_tid, null, reader, null);for (int i = 0; i < writer_number; +i)由于讀者可以同時(shí)獲得鎖,因此提高了系統(tǒng)的并發(fā)程度,進(jìn)而提高了系統(tǒng)的性能。源程序如下:pthread_
21、create(&writer_tidi, null, writer, (void *)i);sleep(1);return 0;void *reader(void *arg)long id = (long)arg;pthread_detach(pthread_self(); while (true)pthread_rwlock_rdlock(&lock);printf(“reader %d is reading the data; “, id); if (p_data = null)printf(“the data is nulln“);elseprintf(“the data is (%d, %f)n“, p_data->i, p_data->f);pthread_rwlock_unlock(&lock);return (void *)0;void *writer(void *arg)pthread_detach(pthread_self();while (true)pthread_rwlock_wrlock(&
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國(guó)高濃度造紙黑液提取機(jī)市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)點(diǎn)塑卡通片沖件自動(dòng)鎖市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)抽氣式轉(zhuǎn)杯市場(chǎng)調(diào)查研究報(bào)告
- 2025年中國(guó)座便器排污管市場(chǎng)調(diào)查研究報(bào)告
- 2024年度浙江省二級(jí)注冊(cè)建筑師之法律法規(guī)經(jīng)濟(jì)與施工每日一練試卷A卷含答案
- 2025年中國(guó)多西他賽無(wú)水物市場(chǎng)調(diào)查研究報(bào)告
- 2024年度浙江省二級(jí)注冊(cè)建筑師之建筑結(jié)構(gòu)與設(shè)備能力提升試卷A卷附答案
- 拆墻工程環(huán)保驗(yàn)收及后期維護(hù)合同
- 休閑農(nóng)業(yè)園場(chǎng)經(jīng)營(yíng)承包管理合同
- 個(gè)體工商戶全流程代理記賬及財(cái)務(wù)分析合同
- 部編版七年級(jí)歷史(下)材料論述題專項(xiàng)訓(xùn)練
- 年產(chǎn)1000噸乳酸的生產(chǎn)工藝設(shè)計(jì)
- 博克服裝CAD制版說(shuō)明操作手冊(cè)(共95頁(yè))
- 南開(kāi)中學(xué)小卷數(shù)學(xué)模擬試卷(共3頁(yè))
- 光電效應(yīng)測(cè)普朗克常數(shù)-實(shí)驗(yàn)報(bào)告
- (完整word版)數(shù)據(jù)模型與決策課程案例分析
- 自制桁架移動(dòng)式操作平臺(tái)施工方案
- 物業(yè)服務(wù)參與校園文化建設(shè)及舉辦大型活動(dòng)配合措施
- 太陽(yáng)能LED路燈項(xiàng)目實(shí)施方案
- 調(diào)崗調(diào)薪實(shí)操指引PPT課件
- 福清核電廠輻射防護(hù)生產(chǎn)準(zhǔn)備實(shí)踐
評(píng)論
0/150
提交評(píng)論