Linux课程设计报告书_第1页
Linux课程设计报告书_第2页
Linux课程设计报告书_第3页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

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

文档简介

1、滨江学院课程设计报告题 目 Linux课程设计院系计算机系专业软件工程学生姓名 学 号2014年6月11日、 Shell编程题(1)编写一个shell脚本,求费波纳奇数列的前 20项及总和。bianltan9=l; re5ultl=0; resultz=o; resultSsB;count=9while $t>tanltang - le 28 doif Sbtanltang -eq 1 thenLet resultlllet 匚aunt+=resultllet resultSresultleltf $t>tanltang -eq 2 th&Olet resulr2=llet

2、 count+=result2Let reulti=r&sult2elselet r&$ult3=re$ultl+re$ultzlet re4ulti»result2l亡t reskjtt2=result3let courit+-re$uLt3ftecho "第SbtanLiang个的偵冷:$result3bh let bianLiang+=idoneecho "前的项总和为;$CQunt"运行结果如图:ddee第壬个的值为 第了个的值为 弟4个的佰为 见5个的值为ro&tubuntu:-/testLtnuxw basfi tes

3、t 1 第个的值为注陣圧个的值为油 第丁个的值为:均 弟*个的佰为:“ 第9个的值为:却 弟个的值为汚5 第近个的值尢汨9 i第圮个的值尢 净箱个的HJ:233 第二4个的值1:377 圭15个的盘为 第沾个的債沟"飾 第订个的(H尢:1M7 第工8亍的fH:2584 第站个的值 第狮个的值为= 6765 前:!B项总和为:17710|厂oof會 在根目录下有四个文件m1.txt ,m2.txt ,m3.txt , m4.txt,用Shell 编程,实现自动创建 m1,m2,m3,m4四个目录,并将m1.txt,m2.txt,m3.txt,m4.txt四个文件分别拷贝到各自相应的目录

4、下。程序运行之前目录结果如下:rootubuntu:nuxM IsHl* txt txt hS + txt pi4 txt testl test3 test4 tests rot$ubuntu:- /teSitLinuK? |程序源码如下:if tbe-ftfor I cp n done运行之后目录结构如下:rootubuntu:-/testLinbash testJ rooteub(jntu:-/te5tLtnuKrf Isml n 1. t>t nZ n2»txt n3h4 M* txt testl test3 test4 teatsrootubuntutestLirnjx

5、# Is ml/ mi.txrrootubuntui/testLinuK# |(3)编写shell程序,使得使用者输入一个文档名,做出以下判断:a) 这个文件是否存在,若不存在则给予一个"File name does not exist”的信息,并中断程序;b) 若这个文件存在,则判断他是个文件或目录,结果输出"Filename is regular file或"File name is directory”;c) 判断一下,运行者的身份对这个文件或目录所拥有的权限,并输出权限数据!输入一个不存在的目录结果如下:rootubuntu:-/testLinux# ba

6、sh test4Please Input a filename,!*11 check the ftlenane1s type and its permissions.Please input a filename:a beIhe filenarc DO HOT exist!rootut)untu:*/tetLinux# |程序源码如下:echo% f il严L rector j ?erhopl MU亠s.二七亠:Is eddflleraarietest&& Cho '&S exittest!站 echoEE exit=Htest&& =test&

7、amp;& =test-w SfHollar4 KU.=edi©Tilt ftlen»*i 皂t ho*h£ mjlb f m"输入一个已存在的目录,得到权限信息如下:-/tcstLinux# bdsh tcst4Please input a filename,1*11 check the filename * £ type and its pernissione.Pleose input a flvcnanc;nl+txtThe fllendnetni.tKt ts a regulere rile,And the pcrnission

8、s is readable writcoblc»rcotubuntu:-/testLinkix# |(4)设计一个shell程序cuts ,它由标准输入读取数据,获取由第一个参数 n和第二个参数m所限定范围的数据,n和m都是整数。即从输入的字符串中抽取第n个字符至第m个字符之间的所有字符(包括这两个字符)。例如:键盘输入)$cuts 11 14This is a test of cuts program ( test ( 显示结果)程序源码如下: Ji j r n j ri n 电 Fi|U if 1/ LI 1/ wu 3rl 1 read line echo|cut,1 - C

9、7 "nt * Lpp程序运行结果如下:rcotubuntu:'/testLtnuxs bash tests 11 14 This is test of cuts progrrt testrootubuntui'/testLlnuxff |'j二、 Linux下C语言程序设计一课程设计Linux下用C语言进程实现#in clude< uni std.h>#in clude<stdio.h>#in clude</usr/ in clude/sys/types.h>#in clude<stri ng.h>main (

10、)pid_t pid1,pid2;char str120,str220;if(pid 1= vfork()<0)perror(”创建子进程一错误!n");exit(0);else if(pid1=0)printf("输入字符串一:”);sca nf("%s",str1); exit(0);if(pid2=vfork()<0)perror(”创建子进程二错误!n");exit(0);else if(pid2=0)printf("输入字符串二:");sca nf("%s",str2);exit(0

11、);waitpid(pid1,NULL,0);waitpid(pid2,NULL,0);prin tf("你输入的字符串一 :sn",str1);prin tf("你输入的字符串二:sn",str2); #in clude<sig nal.h>#in clude< uni std.h>#in clude<stdio.h>#in clude<stdlib.h>#in clude<sys/types.h>#in clude<sys/stat.h>#in clude<fc ntl.h

12、>#in clude<sys/ipc.h>#in clude<sys/shm.h>#defi ne key 1024#defi ne size 160static void sig n(i nt);int shmid;char* shmaddr;main ()pid_t pid;char str20;shmid=shmget(key,size,IPC_CREAT|0600);if(pid=fork()<0)perror(”创建子进程错误!n");exit(0);else if(pid=0)if(sig nal(SIGUSR1,sig n)=SIG_

13、ERR)printf("SIGUSR1 错误!n");exit(0);pause();printf(”子进程结束!n");exit(O);sleep(1);shmaddr=(char*)shmat(shmid,NULL,O);printf("请输入字符串:”);scan f("%s",str);strcpy(shmaddr,str);shmdt(shmaddr);kill(pid,SIGUSR1);wait();shmctl(shmid,IPC_RMID,NULL);static void sig n(i nt sig nnum)in

14、t fd;char* shmaddr;if(sig nnu m=SIGUSR1)prin tf("子进程接收到 SIGUSR1.n"); shmaddr=(char*)shmat(shmid,NULL,0);if(fd=ope n( "testfile.txt",O_RDWR|O_CREAT|O_TRUNC)=-1) prin tf("n打开文件错误! n");return 0;elseprin tf("写入:%sn ”,shmaddr);write(fd,shmaddr,20);close(fd); shmdt(shmad

15、dr);运行结果:anneanna MS-7623;S BC examples.desktop 公弭购 验 4 H 陋呉 史榜 T<!普乐 虞圍 artnaann-MS 76?3:cd Cannanna-MS-76Is1 l.cannaanna MS 7623:/C$ gcc © 1 l.cl.c; Tn function "nain":tfecUratin of built - in declaration Qt built in rilarati&n of built-in declaration of built-infunction *exi

16、tp function 'exit* funetioh *exitf function *exit*i乂;14:warninginmpatibleimplicitl.c:Z0:warning:incoapotil>leinpllcltl_c:26:warning:incoMpatibleimplicitl,c:32:warning:incompatibleimplicitannaanna-HS-762$;-/C$ ./I 航人字符雷一 :asd 琲人宇将田二:dsa坏茅人的亭符串一:aid 林确人的字蒂粛二:阳3 annaanna-MS-7625:'/CS annaann

17、a MS-7623:gcc -o 1 l.cgcc: l.c:沮青翟吓文存或翅擴gcc: no Input fileannnF)a-MS-7&23:-5 cd Cannaanna-MS-7623:/$ gcc -o 1 1.cl.c: In function 'main':l.c:斗4: warniog: inconpatible implicit declaration of built-in fuflttion qstrcpyf Let In function isign,:l.c:62; warning: (returnJ with a value, in function returning void-MS- 7623:/CS /1请唏入字苻串:asda 子 ifil? J#iftS*JSIGUSRl.同 A:ada子避穆靖朿!nnnn-M$-7W3:|实验总结通过这次实验,大致对lin ux有一个系统的了解,能在li

温馨提示

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

评论

0/150

提交评论