freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

[互聯(lián)網(wǎng)]linux程序設(shè)計(jì)——技術(shù)技巧與項(xiàng)目實(shí)踐---第10章-資料下載頁

2024-12-07 22:37本頁面
  

【正文】 d) { ? printf(I39。m the child\n)。 ? exit(0)。 } ? else if (pid0) { ? wait(NULL)。 ? printf(I39。m the parent,child has pid %d\n,pid)。 ? } ? else ? printf(Fork fail!\n)。 ? } 2022/1/3 67 ? 4. 管道通信程序調(diào)試。錄入、編輯、調(diào)試、運(yùn)行程序,記錄結(jié)果并加注釋。 ? include ? include ? includesys/ ? main() ? { int fd[2],nbytes。 ? pid_t childpid。 ? char string[]=Hello! \0。 ? char readbuffer[80]。 ? pipe(fd)。 ? if ((childpid=fork())==1) ? { perror(fork)。 ? exit(1)。 } ? if (childpid==0) ? { close(fd[0])。 ? write(fd[1],string,strlen(string))。 ? close(fd[1])。 ? } ? else ? { ? close(fd[1])。 ? nbytes=read(fd[0],readbuffer, ? sizeof(readbuffer))。 ? printf(Received string:%s\n, ? readbuffer)。 ? close(fd[0])。 ? } ? } 2022/1/3 68 ? 5. Gdb調(diào)試 ? Linux特色源于 shell的 GNU調(diào)試器,稱作 gdb。gdb可以查看程序的內(nèi)部結(jié)構(gòu)、打印顯示變量值、設(shè)斷點(diǎn),單步調(diào)試源代碼。功能極其強(qiáng)大,適用于調(diào)試程序代碼中的問題。這里只介紹最基本功能,建議閱讀 gdb手冊(cè)。 2022/1/3 69 下面的清單是一個(gè)有錯(cuò)誤的 C源程序 。 ? /* */ ? 1 include ? 2 ? 3 static char buff [256]。 ? 4 static char* string。 ? 5 int main () ? 6 { ? 7 printf (Please input a string: )。 ? 8 gets (string)。 ? 9 printf (\nYour string is: %s\n, string)。 ? 10 } ? /* */ ? 這個(gè)程序簡單,目的是接受用戶輸入,再將用戶輸入打印出來。其中用了未經(jīng)初始化的字符串 string,編譯運(yùn)行后,出現(xiàn)了 Segment Fault 錯(cuò)誤: ? $ gcc o bugging g ? $ ./bugging ? Please input a string: asfd ? Segmentation fault (core dumped) 2022/1/3 70 ? 為了查找該程序中出現(xiàn)的問題,我們利用 gdb,并按如下的步驟進(jìn)行: ? ( 1)運(yùn)行 gdb bugging 命令,裝入 bugging 可執(zhí)行文件; ? ( 2)執(zhí)行裝入的 bugging 命令 run; ? ( 3)使用 where 命令查看程序出錯(cuò)的地方; ? ( 4)利用 list 命令查看調(diào)用 gets 函數(shù)附近的代碼; ? ( 5)唯一能導(dǎo)致 gets函數(shù)出錯(cuò)的是變量 string。用 print查看 string值; ? ( 6)在 gdb中,可以直接修改變量值,只要將 string取一個(gè)合法指針值就可以了,為此,在第 8行處設(shè)置斷點(diǎn) break 8; ? ( 7)程序重新運(yùn)行到第 8行停止,這時(shí)用 set variable命令修改 string值; ? ( 8)繼續(xù)運(yùn)行,將看到正確的程序運(yùn)行結(jié)果。 2022/1/3 71 ? 6.多文件自動(dòng)編譯的實(shí)現(xiàn) ? 在 Unix 上寫過程序的人都遇到過 Makefile,尤其是用 C 開發(fā)程序的人。用 make 開發(fā)和編譯程序很方便,但要寫一個(gè) MakeFile就不簡單了,許多人聞 Unix色變。這里只介紹如何利用 GNU Autoconf 及 Automake 這兩款軟件幫助自動(dòng)產(chǎn)生 Makefile文件的過程,具體細(xì)節(jié)請(qǐng)參見本書的,相信讀者再練習(xí)一次會(huì)更有收獲的。 ? 在開始使用 Automake前,首先確認(rèn)系統(tǒng)里安裝有如下的幾款 GNU軟件: Automake、 Autoconf、 m perl和Libtool (如果需要生成 shared library)。 ? 建議使用 GNU的 C/C++ 編譯器、 GNU Make及其它 GNU工具程序作為開發(fā)環(huán)境,這些工具屬于 Open Source Software,免費(fèi)且功能強(qiáng)大。如果使用 Red Hat Linux可以找到所有上述軟件的 rpm文件, FreeBSD也有現(xiàn)成的package可用,也可以自行下載這些軟件的源碼再安裝。 2022/1/3 72 實(shí)踐項(xiàng)目六 內(nèi)存動(dòng)態(tài)分區(qū)管理 實(shí)踐目的 ? 。 ? 。 ? 。 實(shí)踐內(nèi)容 ? 寫一個(gè)程序 ,模擬實(shí)現(xiàn)內(nèi)存的動(dòng)態(tài)分區(qū)分配算法。假設(shè)內(nèi)存大小為 100K。 ? 、最佳適應(yīng)算法分配內(nèi)存空間。 ? 。 ? 。 2022/1/3 73 實(shí)踐程序及分析 ? 本程序的源代碼如下: ? /* 進(jìn)入程序后可以根據(jù)菜單項(xiàng)進(jìn)入不同的模塊 */ ? /* 1. 使用首次適應(yīng)算法分配空間 */ ? /* 2. 使用最佳適應(yīng)算法分配空間 */ ? /* 3. 釋放 塊空間 */ ? /* 4. 顯示內(nèi)存分配情況 */ ? /* 5. 退出系統(tǒng) */ ? /**/ ? include ? include ? include ? define MEMSIZE 100 /*定義內(nèi)存大小為 100*/ ? define MINSIZE 2 /*分配時(shí)如果剩余值小于此值則不再分割 */ ? typedef struct MemoryInformation{ /*空間分區(qū)表結(jié)構(gòu) */ ? int start。 /*起始地址 */ ? int size。 /*大小 */ ? char info。 /*狀態(tài) :39。f39??臻e (FREE): 39。u39。占用 (USED)。 39。e39。表結(jié)束 (END)*/ ? }MEMINFO。 2022/1/3 74 ? MEMINFO MemList[MEMSIZE]。 ? void Display()。 ? /**/ ? /*函數(shù)名 :InitAll() */ ? /*功能 :初始化所有變量。 */ ? /**/ ? void InitAll() { ? int i。 ? MEMINFO temp={0, 0, 39。e39。}。 ? for(i=0。iMEMSIZE。i++) ? MemList[i]=temp。 ? MemList[0].start=0。 ? MemList[0].size=MEMSIZE。 ? MemList[0].info=39。f39。 ? } ? /**/ 2022/1/3 75 ? /*函數(shù)名 FirstFitnew() */ ? /*功能 :使用首次適應(yīng)算法分配內(nèi)存 */ ? /**/ ? void FirstFit_new() { ? int i, j, size。 ? char temp[10]。 ? printf(How many MEMORY do you require?)。 ? scanf(%d,amp。size)。 ? for(i=0。iMEMSIZE1amp。amp。MemList[i].info!=39。e39。i++) { ? if(MemList[i].size=sizeamp。amp。MemList[i].info==39。f39。) { ? if(MemList[i].sizesize=MINSIZE) ? MemList[i].info=39。u39。 ? else { ? for(j=MEMSIZE2。ji。j) { ? MemList[j+1]=MemList[j]。 ? } ? MemList[i+1].start=MemList[i].start+size。 ? MemList[i+1].size=MemList[i].sizesize。 ? MemList[i+1].info=39。f39。 ? MemList [i].size=size。 ? MemList[i].info=39。u39。 ? } ? break。 ? } ? } 2022/1/3 76 ? if(i==MEMSIZE1|| MemList[i].info==39。e39。) { ? printf(NOT Enough Memory!!\n)。 ? getchar()。 ? } ? Display()。 ? } ? /**/ 2022/1/3 77 ? /*函數(shù)名 :BestFit_new() */ ? /*功能 :使用最佳適應(yīng)算法分配內(nèi)存 */ ? /**/ ? void BestFit_new() { ? int i, j, k, flag, size。 ? char temp[10]。 ? printf(How many MEMORY requir?)。 ? scanf(%d,amp。size)。 ? j=0。 ? flag=0。 ? k=MEMSIZE。 ? for(i=0。iMEMSIZE1amp。amp。MemList[i].info!=39。e39。i++) { ? if(MemList[i].size=sizeamp。amp。MemList[i].info==39。f39。) { ? flag=1。 ? if(MemList[i].sizek) { ? k=MemList[i].size。 ? j=i。 ? } ? } ? } 2022/1/3 78 ? i=j。 ? if(flag==0) { ? printf(NOT Enough Memory!!\n)。 ? getchar()。 ? } ? else if(MemList[i].sizesize=MINSIZE) ? MemList[i].info=39。u39。 ? else { ? for(j=MEMSIZE2。ji。j) { ? MemList[j+1]=MemList[j]。 ? } ? MemList[i+1].start=MemList[i].start+size。 ? MemList[i+1].size=MemList[i].sizesize。 ? MemList[i+1].info=39。f39。 ? MemList[i].size=size。 ? MemList[i].info=39。u39。 ? } ? Display()。 ? } 2022/1/3 79
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1