操作系统linux版实验报告_第1页
操作系统linux版实验报告_第2页
操作系统linux版实验报告_第3页
已阅读5页,还剩23页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、操作系统实验报告(Linux版)网络142 潘豹 142999实验一 观察Linux进程状态一、实验目的在本实验中学习Linux操作系统的进程状态,并通过编写一些简单代码来观察各种情况 下,Linux进程的状态,进一步理解进程的状态及其转换机制。二、实验环境硬件环境:计算机一台,局域网环境;软件环境:Linux Ubuntu操作系统,gcc编译器。(四)查看不可中断阻塞”状态(D)创建一个 C程序,如uninter_status.c,让其睡眠30s代码:#in clude< uni std.h>#in clude<stdio.h>int mai n()int i=0,j

2、=0,k=0;for(i=0;i<1000000;i+)for(j=0;j<1000000;j+) k+;k-;实验结果:0 l studentlab-soFt:studentlab-softIs“exanples. desktop金共的 AM 视flf图片 丈林 T fi 誉乐 桌面 studentlab-5oft cd 桌荷 studentleb-soft:-/桌面$ gcc 1»1 *c -o 1*1studentglab-soft桌面$ . / 1.1 & ps1 3821PIDTTYTIMECMD3757pts/100:QQ:00bash3821pts/

3、100:00:ae1.13822Pts/l00:00:00Plstudent1ab-soft:-/A |(二)查看“暂停”状态(T)运行run_status进程,其进入 R状态:代码同上:(三)查看 可中断阻塞”状态(S)创建一个C程序,如interruptiblie_status.c,让其睡眠 30s编译链接,后台运行该程序(后接 &符号),并使用ps命令查看运行状态 代码:#in clude< uni std.h>#in clude<stdio.h>int mai n()sleep(30);return;实验结果:pdnpan-Y400: Dan9pan-Y

4、4eo;-$ gcc 1.2, ci In function *nain";1.2. c:613 * uarntng: * roturn" iwith no value, in function returning non-void retur n;ApanpaB-Y4ee:*$ftps'll 4522Plt> TTYTIMECMD4566 pts;2800:06:99bash4522 pt5;2000;GG:OD1.2452孑 pts/2990:3:06pantapan-Y460|(四)查看不可中断阻塞”状态(D)创建一个 C程序,如uninter_stat

5、us.c,让其睡眠30s编译链接,后台运行该程序(后接 &),并使用ps命令查看运行状态 代码:#in clude< uni std.h>#in clude<stdio.h>int mai n()if(vfork()=0)sleep(300);return;实验结果:空令 Q panpan-Y400; «panpan-Y406:q匚匸 1-4”匚-a 1*4 P3npan-Y40e;-$ /l*4 8 ps1 444SPIDTTYTIME4425pts/1900;;eo;oeb»h4445pts/1900;00;001.44446pts/19

6、00 :00P54447pts/19D9::e0:o1,4panpan-y49e:-$ |(五)查看 僵尸”进程(Z)创建一个C程序,如zombie_status.c,在其中创建一个子进程,并让子进程迅速结束, 而父进程陷入阻塞编译链接,后台运行该程序(后接&),并使用ps命令查看运行状态(30s内)代码:#in clude< uni std.h> #in cldue<stdio.h> int mai n()if(fork()sleep(300);实验结果:e O 衣 panpan-Y400: -n -Y466: *$ g匚匚 1.51,5pangpan-Y40

7、O:-$ ,/l + 5 S ps L 4232PIDTTYTIME4214pts/690:69:00bs呂h4232pt£/000;0 91001.54233ptS/000:00:00PS4234pts/000:60:6014 5 «defunct>panpan-Y40e:*$ |实验二 观察Linux进程/线程的异步并发执一、实验目的通过本实验学习如何创建 Linux进程及线程,通过实验,观察 Linux进程及线程的异步 执行。理解进程及线程的区别及特性, 进一步理解进程是资源分配单位,线程是独立调度单位。二、实验环境硬件环境:计算机一台,局域网环境;软件环境:L

8、inux Ubuntu操作系统,gcc编译器。三、实验内容和步骤1、进程异步并发执行编写一个C语言程序,该程序首先初始化一个count变量为1,然后使用fork函数创建两个子进程,每个子进程对 count力口 1后,显示"I am son, count=x ”或"am daughter, count=x ",父进程对 count力口 1之后,显示"I am father, count=x ",其中x使用count值代替。 最后父进程使用 waitpid等待两个子进程结束之后退出。编译连接后,多次运行该程序,观察屏幕上显示结果的顺序性,直到出现不

9、一样的情 况为止,并观察每行打印结果中count的值。代码:#in cludev uni std.h>#in clude<stdio.h>int mai n()pid_t son _pid,daughter_pid;int coun t=1;son _pid=fork();if(son _pid=O)coun t+;prin tf("i am son,coun t=%dn",co un t);elsedaughter_pid=fork();if(daughter_pid=O)coun t+;prin tf("i am daughter,co un

10、 t=%d n",co un t);elsecoun t+;prin tf("i am father,co un t=%dn",co un t); waitpid(son_pid,NULL,0); waitpid(daughter_pid,NULL,O);QL panbao>ldieapad-y400: pMbHgt<ieapad>y4Mcd 束面 panbaoOtdeapdd:qcc x.c -o x x.c: in function Fin':xc:25:5: warntny: inplLcit declaration of func

11、tion aitpid* Winplicit functi on-declarationMAltpLdsan_ptd»NULL,e);ApanbaoQldeapad-y4M: #桌面$ ./ki an fatherFcount=2 I an son,counts t an daugliter, ccunt=2 panbaotdeapdd-y4ae:,/x t an fatherxount=2 t an ,count=z t an daughter,count-2 panbaotdedpad-yOO:./x t an father,count=2 i en ddught證r匚Qunt=

12、2 t an son,countsDBin tascj曲irleaiD召d ¥4B6i : “虛面5 2、线程异步并发执行编写一个C语言程序,该程序首先初始化一个 count变量为1,然后使用pthread_create 函数创建两个线程,每个线程对 count加1后,显示"I am son, count=x ”或“m daughter, count=x ",父进程对 count力口 1之后,显示"I am father, count=x ",其中x使用count值代替。 最后父进程使用 pthread_join等待两个线程结束之后退出。编译连

13、接后,多次运行该程序,观察屏幕上显示结果的顺序性,直到出现不一样的情 况为止,并观察每行打印结果中count的值。代码:#in clude< uni std.h>#in clude<stdio.h>#i nclude<pthread.h>void *daughter(void *num)int* a=(i nt *)num;*a+=1;prin tf("i am daughter,co un t=%d n",*a);void *son( void *num)int* a=(i nt *)num;*a+=1;prin tf("i

14、am son,coun t=%dn",*a);int mai n()pthread_t son _tid,daughter_tid;int coun t=1;pthread_create(&son _tid,NULL,so n,&coun t);pthread_create(&daughter_tid,NULL,daughter, &count); coun t+;prin tf("i am pare nt,co un t:=%dn",co un t);pthreadoin (son_tid,NULL);pthreadoi n(da

15、ughter_tid,NULL);return 0;实验结果:0 巴p<an bd o d-40 0; f 面/tmp/ccNFcOEf.cl 在函8 中:b.c: ( . text+0xbl) 2 #ptlhread create p 定义理弓用 bc:( text+Dx匚亡):*pthreadl_create ,耒走义的引用 b+ = : («: *'pthreadi_ jo Ln' 义躺引穽 bciGtext+SKlNl):对*pthread_j&ln*耒定文的耳I用 011rctZi error: Id returned T exit statu

16、spagcc '02 -wall o b b.c -Ipttirndbc: In functtcn "divhter":; 1: wcr-ilngi control reaches tnd of non-void funttifln -return-type 戸Ib.c: Lfi furttion * son * :b. e: 15:1: h a rntng : control reached end af fion-votd tunettcn -Wr eturn-type J I Apjnbjotdejpjd-yOft:- /'f,/bit ar% par

17、ent,count :=;1 disuqhrer (counts flIt. 3“ son pccunt-3panbdo6idedpad-y4e3;-f'XS ./bX an sonjCount=Jt ar parent.sunt;=31 an daughter,caLjnt=4实验三 使用信号量进行互斥与同步、实验目的本实验介绍在Linux中使用信号量进行进程同步、互斥的方法。读者可以通过实验进一 步理解进程间同步与互斥、临界区与临界资源的概念与含义,并学会Linux信号量的基本使用方法。、实验环境硬件环境:计算机一台,局域网环境;软件环境:Linux Ubuntu操作系统,gcc编

18、译器。、实验内容和步骤三、实验内容和步骤(一) 参考:POSIX 以及 System VSystem V: Unix众多版本中的一支,最初由 AT&T定义,目前为第四个版本,其中定义 了较为复杂的API。POSIX: Portable Operat ing System In terface , IEEE 为 了统一 Un ix 接口而定义的标准, 定义了统一的 API接口。Linux即支持System API,又支持 POSIX API(二) 实验步骤step1 :通过实例查看不使用互斥时的情况(假设文件命名为n o_sem.c)编译链接,同时运行两个进程,显示结果代码:#in cl

19、ude<stdio.h>#in clude<stdlib.h>int main (i nt argc,char *argv)char message='x'int i=0;if(argc>1)message=argv10;for(i=0;i<10;i+)prin tf("%c",message);fflush(stdout);sleep(ra nd()%3);prin tf("%c",message);fflush(stdout);sleep(ra nd()%2);sleep(10);exit;实验结果

20、:pan$pan-r4G0:-$ gedit panapan>Y4e£):$ get x.c -d x gcc: error, z 没有那个文件或目录 gee: l err : no input files compLldtLon tt-f nlndted. panpan-v4G0cd 桌面 panpan -Y40B面名 gcc x r c - xIn function "rilin'>.c:13:2: warning: inpliclt decXaratton of function fsl«ep' function -declara

21、tionsleep( rdnd()363);Apanpan-¥4ee:-/桌面S ,/x & Jx o1 7117step2 :使用信号量来对临界资源进行互斥(假设文件命名为with_sem.c)编译链接,同时运行两个进程。观察X和0的出现规律,并分析原因。代码:#in clude<stdio.h>#in clude<stdlib.h>#in clude<sys/types.h>#in clude<sys/ipc.h>#in clude<semaphore.h>#in cludevfc ntl.h>#in cl

22、ude<sys/stat.h>int main (i nt argc,char *argv)char message='x:int i=0;if(argc>1)message=argv10;sem_t *mutex=sem_ope n("mysem",O_CREAT,0666,1);for(i=0;i<10;i+) sem_wait(mutex);prin tf("%c",message);fflush(stdout);sleep(ra nd()%3);prin tf("%c",message);ffl

23、ush(stdout);sem_post(mutex);sleep(ra nd()%2);sleep(10);sem_close(mutex);sem_ un li nk("mysem");exit(0);实验结果:* r panpan-Y4Q0: 面In functiQn *rtain *:x.c:22:2: warning: tnplVcVt declaration of Function r slvspF -wtmpltclt- function -declarationsleep(rand()X3);A/tnp/ccAkHkxZ.o:在Stkain*中:x.c: (

24、. taxt+Bx4b)I 对r sen_opn * 未定爻的弓用 x*c:( rtext+Bx67): sen_wait定义的目用 x*c: (. text-i-0xd6):对r senposr *耒定义的弓用 x,c: (. text+exl23)' 对'肚Ejrlmh未定义的引用 x*c: (. textSxl2d):对"he” unlink'未定义的引用 col.Iect2: error r Id r eturned 1 pj(lt panflpan*Y400;*/桌而$ gcc Lpthread x.c o x gcc-lpthread:未找到祈令Y

25、4OQ:"/4lgcc x*c -lipthread -o xx£: In functicin *rtavn *:x.c:22:2: warning t tnpl lc1_t declaration of Function * &leep * - Htnip licit - function -declaration$lcep(rand()X3);ApM9pan«Y40B: */jK面$ ./x,/x 1刖血XXOOXXOGXXOOXXOOXXOOXKGOXXO0XXOOMKOOXXOO1 已完成J 热pan电pn” 丫4DE:_/桌面$ step3 :使

26、用信号量来模拟下象棋红黑轮流走子的情况编写两个C语言程序black_chess.c以及red_chess.c,分别模拟下象棋过程中红方走子 和黑方走子过程。走子规则:红先黑后,红、黑双方轮流走子,到第10步,红方胜,黑方输。代码:红色棋#in clude<stdio.h>#in clude<stdlib.h>#in clude<sys/types.h>#in clude<sys/ipc.h>#in clude<semaphore.h>#in cludevfc ntl.h>#in clude<sys/stat.h>in

27、t main (i nt argc,char *argv)int i=0;sem_t *hei=sem_ope n("chess_black_sem",O_CREAT,0666,1);sem_t *ho ng=sem_ope n( "chess_red_sem",0_CREAT,0666,0);for(i=0;i<10;i+) sem_wait(hei);if(i!=9)prin tf("Red chess had moved,black,chess go!n");elseprin tf("Red chess win!

28、n ”); fflush(stdout);sem_post(h on g);sleep(10);sem_close(hei);sem_close(h on g);sem_ un li nk("chess_red_sem");sem_ un li nk("chess_black_sem");exit(0);黑色棋:#in clude<stdio.h>#in clude<stdlib.h>#in clude<sys/types.h>#in clude<sys/ipc.h>#in clude<semapho

29、re.h>#in clude<fc ntl.h>#in clude<sys/stat.h>int main (i nt argc,char *argv)int i=0;sem_t *hei=sem_ope n("chess_black_sem",O_CREAT,0666,1); sem_t *ho ng=sem_ope n("chess_red_sem",0_CREAT,0666,0); for(i=0;i<10;i+)sem_wait(h on g);if(i!=9)prin tf("Black chess

30、 had moved,red chess go!n");elseprin tf("Black chess win!n ”);fflush(stdout);sem_post(hei);sleep(10);sem_close(hei);sem_close(h on g);sem_ un li nk("chess_red_sem");sem_ un li nk("chess_black_sem");exit(0);实验结果:panpan-Y400: */臬面 panpan-Y40e:面$ ./厂Ed & ./block 1 3677

31、Red chess had movedblack,ch&ss go! Black chess had moved rred chess go! Red chess had moved,bla匚k*匸hiss go! Black chess had moved,red chess go! Red chess hdd movedfblackche-ss go Black 匚hess had Hoved>red 匚hess go! Red chss had moved,black,che-ss go! Black 匚hess had moved,red chess go J Red c

32、hess h诃d movedtblack,chess go! Black chess had moved,red chess go! Red chess h占d moved,black,chess go Black 匚hess had moved,red chess go! Red ch&ss hd moved,black,ch&ss go! Black chess had moved,red ch&ss go! Red chess hwd movedfblack,chess go! Black chess had moved>red chess go! Red

33、chess had movedTblack,chgo< Black 匸hess had moved,red chess go J Red ch&ss win!Slack chess win!i+已完成JEdpanpanY406:*/桌面$ I实验四作业调度算法模拟、实验目的(1) 掌握周转时间、等待时间、平均周转时间等概念及其计算方法。(2) 理解五种常用的进程调度算法( FCFS SJF HRRF、HPF、RR),区分算法之间的 差异性,并用C语言模拟实现各算法。(3) 了解操作系统中高级调度、中级调度和低级调度的区别和联系。、实验环境硬件环境:计算机一台,局域网环境;软件环境

34、:Linux Ubuntu操作系统,gcc编译器。、实验内容和步骤本实验所选用的调度算法均默认为非抢占式。 实验所用的测试数据如下表所示。本实验所用的测试数据如下表所示表实验测试数据作业Id到达时间执行时间优先权180050028153013830252483520258451526700101782050作业的数据结构: typedef struct nodeint nu mber; / 作业号int reach_time;作业抵达时间int need_time; 作业的执行时间 in t privilege;/ 作业优先权 float excelle nt;响应比int start_tim

35、e;作业开始时间int wait_time;等待时间in t visited;/ 作业是否被访问过 bool isreached;/ 作业是否已经抵达 job;代码:#i nclude <stdio.h>#in clude <stri ng.h> #i nclude <stdlib.h> #in clude<stdbool.h>/最大作业数量const int MAXJOB=50;/作业的数据结构 typedef struct nodeint number;/ 作业号int reach_time;/作业抵达时间 int need_time;/作业

36、的执行时间 int privilege;/作业优先权 float excellent;/ 响应比 int start_time;/作业开始时间 int wait_time;/ 等待时间 int visited;/作业是否被访问过 bool isreached;/作业是否抵达 job;job jobs50; 作业序列int quantity;/ 作业数量/初始化作业序列void in itial_jobs()int i;for(i=0;i<MAXJOB;i+)jobsi. nu mber=0;jobsi.reach_time=0;jobsi.privilege=0;jobsi.excell

37、e nt=0;jobsi.start_time=0;jobsi.wait_time=0;jobsi.visited=0;jobsi.isreached=false;qua ntity=O;/重置全部作业信息void reset_ji nfo()int i;for(i=0;i<MAXJOB;i+)jobsi.start_time=0;jobsi.wait_time=0;jobsi.visited=0;,若无返回-1/查找当前current_time已到达未执行的最短作业int fin dminjob(job jobs,i nt count)int minjob=-1;/=jobs0. ne

38、ed_time;int min loc=-1;int i;for(i=0;i<co un t;i+)if(mi nloc=-1)if( jobsi.isreached=true && jobsi.visited=0) minjob=jobsi. need_time;min loc=i;else if(minjob>jobsi. need_time&&jobsi.visited=0&&jobsi.isreached=true) minjob=jobsi. need_time;min loc=i;return mi nloc;/查找最早到

39、达作业,若全部到达返回-1.int fin drearlyjob(job jobs,i nt count)int rearlyloc=-1;int rearlyjob=-1;int i;for(i=0;i<co un t;i+)if(rearlyloc=_1)if(jobsi.visited=0)rearlyloc=i;rearlyjob=jobsi.reach_time;else if(rearlyjob>jobsi.reach_time&&jobsi.visited=0)rearlyjob=jobsi.reach_time;rearlyloc=i;return

40、rearlyloc;/读取作业数据void readJobdata()FILE *fp;char fname20;int i;/输入测试文件文件名prin tf("please in put job data file n amen");sca nf("%s",fname);if(fp=fope n(fname,"r")=NULL)prin tf("error, ope n file failed, please check file name:' n");else/依次读取作业信息while(!feof(

41、fp)if(fscanf(fp,"%d %d %d %d",&jobsquantity.number,&jobsquantity.reach_time,&jobsquantity .n eed_time,&jobsqua ntity.privilege)=4)qua ntity+;/打印作业信息prin tf("output the orig in job datan");printf("n");prin tf("tjoblDtreachtimet needtimetprivilegen&qu

42、ot;);for(i=0;i<qua ntity;i+)prin tf("t%-8dt%-8dt%-8dt%-8dn",jobsi. number,jobsi.reach_time,jobsi. need_time,jobsi .privilege);/FCFSvoid FCFS()int i;int curre nt_time=0;in t loc;int total_waitime=0;int total_r oun dtime=0;/获取最近到达的作业loc=fi ndrearlyjob(jobs,qua ntity);/输出作业流printf("nn

43、FCFS 算法作业流 n”);n");prin tf("tjobIDtreachtimetstarttimetwaittimetro un dtimen");curre nt_time=jobsloc.reach_time;/每次循环找出最先到达的作业并打印相关信息for(i=0;i<qua ntity;i+)if(jobsloc.reach_time>curre nt_time)jobsloc.start_time=jobsloc.reach_time;curre nt_time=jobsloc.reach_time;elsejobsloc.star

44、t_time=curre nt_time;jobsloc.wait_time=curre nt_time-jobsloc.reach_time;prin tf("t%-8dt%-8dt%-8dt%-8dt%-8dn",loc+1,jobsloc.reach_time,jobsloc.start_time,job sloc.wait_time,jobsloc.wait_time+jobsloc .n eed_time);jobsloc.visited=1;curre nt_time+=jobsloc .n eed_time;total_waitime+=jobsloc.wai

45、t_time;total_r oun dtime=total_r oun dtime+jobsloc.wait_time+jobsloc .n eed_time;/获取剩余作业中最近到达作业loc=fi ndrearlyjob(jobs,qua ntity);printf(” 总等待时间:%-8d 总周转时间:%-8dn",total_waitime,total_roundtime);printf( “平 均 等 待 时 间 :%4.2f 平 均 周 转 时间:%4.2fn",(float)total_waitime/(quantity),(float)total_roun

46、dtime/(quantity);/短作业优先作业调度void SFJschdulejob(job jobs,i nt count)int mai n()in itial_jobs();readJobdata();FCFS();reset_ji nfo();SFJschdulejob(jobs,qua ntity);system("pause");return 0;实验结果:V409:4面S gcc-a apanlpan-QU:./a please input job data file nane sscutput th origin job dRtwjoblDreacht

47、imeneedtiTcprivilege1sea59e2813G1233S2524S352584515267001017碍決作业流S2&s0joblDreachtimestarttineroufldtiHC67607&8ie1S09aoe2815ase3565782&ase6 &fiS3030365556049359107595总等待时fe:3LG 平均等待时间: sht 1i pause:84936总周转时|'»1:46544.29平沟周转时间:66.43not foundes10Q实验五Linux内存分配、实验目的1、 了解Linux内存的

48、分配和虚拟内存管理的原理,学习如何使用 malloc动态申请内存, 了解动态申请与静态申请的区别。2、 深入理解Linux的内存布局:代码段、数据段、BSS段、堆栈段、堆二、实验环境硬件环境:计算机一台,局域网环境;软件环境:Linux Ubuntu 操作系统,gcc编译器。、实验内容和步骤第一部分:编程分析 Linux中内存动态申请与内存静态申请的区别要求:1、 编写一个Linux C程序,在该程序中使用定义一个全局变量,以及使用malloc申请一段内存(可大于物理内存大小,理论上在32位系统中可以申请小于 3G空间,但由于malloc 要求申请连续的空间,所以能申请到的空间一般在2G以下)

49、。2、 打印出全局变量的起始地址,以及malloc分配的内存的地址;3、观察运行结果,并分析说明结果的地址是否是物理地址。代码:#in clude<stdio.h>#in clude<stdlib.h>in t pin t128;int mai n()char* pbuf=(char *)malloc(sizeof(char)*1024*1024*1024);if(p in t)prin tf("the address of pint is %xn ”,p in t);if(pbuf)prin tf("the address of pbuf is %

50、xn ”,pbuf);if(pbuf)free(pbuf);pbuf=NULL;return 0;实验结果:panpan-Y400:灯鼻面pan3pan-Y4O0:-$ gcc z + c -o zg error r.c:没肩那个文件或冃录gcc:'-r no input filesconpi1ntinn ternihated.panljpan-V460icd 卓面 pan(3pan-Y4O0 135 gcc z . c -a ?zIn funttion rnainJ:zc:9:10: warring; fornatexpects srgunent of type 1 unsigned

51、 int', but argutent 2 has type *intrnat=printf("the address of pint is,pint:Aic; 13:16; ning; forat '%mR eicpecargument of type 1 unsigned ihtr r but argun #nt 2 has typ电'thar * *-Wfornat=Jprintf(k theciF pbuf is 賢»ptjuf;Apdh$pan>¥4Gtl./ztheof pint isthe address of pbuf

52、 is 24cel010 panpmn¥40®T农面$ 第二部分:进一步了解Linux内存的分配和虚拟内存管理的原理、了解Linux的内存布局:代码段、数据段、BSS段、堆栈段、堆。要求:1、编写一个Linux C程序,在该程序中定义初始化全局变量、未初始化全局变量、初始化静态变量、未初始化静态变量、局部变量、使用malloc分配的局部变量2、打印出各种变量的的起始地址代码:#i nclude <stdio.h>#i nclude <stdlib.h> /定义两个初始化的全局变量int data_var0 = 10;int data_var1 = 1

53、0; / 定义两个未初始化的全局变量int bss_var0;int bss_var1;int mai n()/分别定义一个初始化和一个未初始化的静态变量static int data_var2 = 10;static int bss_var2;/定义两个局部变量int stack_varO = 1;int stack_var1 = 1;int stack_var2 = 1;printf(”TEXT Segmentn ”);prin tf("Address of main: %pn", main);printf(”DATA Segmentn ”);prin tf("

54、;Address of data_var0: %pn", &data_varO);prin tf("Address of data_var1: %pn", & data_var1);prin tf("Address of data_var2: %pn", &data_var2);printf(”BSS Segmentn");prin tf("Address of bss_varO(BSS Segme nt): %pn", & bss_var0);prin tf("Addre

55、ss of bss_var1(BSS Segme nt): %pn", & bss_var1);prin tf("Address of bss_var2(BSS Segme nt): %pn", & bss_var2);printf(”STACK Segmentn");prin tf("Address of stack_var0: %pn", &stack_var0);prin tf("Address of stack_var1: %pn", &stack_var1);printf(

56、"Address of stack_var2: %pn", &stack_var2); / 使用 malloc 分配三个大小为 1024B的内存char* heap_varO = (char*)malloc(1024);char* heap_var1 = (char*)malloc(1024);char* heap_var2 = (char*)malloc(1024); / 使用 malloc 分配三个大小为 512MB 的内 存char* mmap_var0 = (char*)malloc(1024 * 1024 * 512);char* mmap_var1 = (char*)malloc(1024 * 1024 * 512);char* mmap_var2 = (char*)malloc(1024 * 1024 * 512);printf(”HEAP Segmentn");if(heap_var0)prin tf("Address of heap_var0:%pn", heap_var0);free(heap_var0); heap_var0 = NULL;if(h

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论