Linux 课程设计报告书.docVIP

  • 19
  • 0
  • 约2.69千字
  • 约 13页
  • 2020-02-04 发布于安徽
  • 举报
.专业整理. .学习帮手. 滨江学院 课程设计报告 题 目 Linux 课程设计 院 系 计 算 机 系 专 业 软 件 工 程 学生姓名 学 号 2014年6月11日 Shell编程题 编写一个shell脚本,求费波纳奇数列的前20项及总和。 运行结果如图: 在根目录下有四个文件 m1.txt,m2.txt,m3.txt,m4.txt,用 Shell 编程,实现自动 创建 m1,m2,m3,m4 四个目录,并将 m1.txt,m2.txt,m3.txt,m4.txt 四个文件分别拷贝到各自相应的目录下。 程序运行之前目录结果如下: 程序源码如下: 运行之后目录结构如下: 编写shell程序,使得使用者输入一个文档名,做出以下判断: 这个文件是否存在,若不存在则给予一个“Filename does not exist”的信息,并中断程序; 若这个文件存在,则判断他是个文件或目录,结果输出“Filename is regular file”或“Filename is directory”; 判断一下,运行者的身份对这个文件或目录所拥有的权限,并输出权限数据! 输入一个不存在的目录结果如下: 程序源码如下: 输入一个已存在的目录,得到权限信息如下: 设计一个shell程序cuts,它由标准输入读取数据,获取由第一个参数n和第二个参数m所限定范围的数据,n和m都是整数。即从输入的字符串中抽取第n个字符至第m个字符之间的所有字符(包括这两个字符)。例如: $cuts 11 14 This is a test of cuts program (键盘输入) test (显示结果) 程序源码如下: 程序运行结果如下: Linux下C语言程序设计—课程设计 Linux下用C语言进程实现 一. #includeunistd.h #includestdio.h #include/usr/include/sys/types.h #includestring.h main() { pid_t pid1,pid2; char str1[20],str2[20]; if((pid1=vfork())0) { perror(创建子进程一错误!\n); exit(0); } else if(pid1==0) { printf(输入字符串一:); scanf(%s,str1); exit(0); } if((pid2=vfork())0) { perror(创建子进程二错误!\n); exit(0); } else if(pid2==0) { printf(输入字符串二:); scanf(%s,str2); exit(0); } waitpid(pid1,NULL,0); waitpid(pid2,NULL,0); printf(你输入的字符串一:%s\n,str1); printf(你输入的字符串二:%s\n,str2); } 二. #includesignal.h #includeunistd.h #includestdio.h #includestdlib.h #includesys/types.h #includesys/stat.h #includefcntl.h #includesys/ipc.h #includesys/shm.h #define key 1024 #define size 160 static void sign(int); int shmid; char* shmaddr; main() { pid_t pid; char str[20]; shmid=shmget(key,size,IPC_CREAT|0600); if((pid=fork())0) { perror(创建子进程错误!\n); exit(0); } else if(pid==0) { if(signal(SIGUSR1,sign)==SIG_ERR) { printf(SIGUSR1错误!\n); exit(0); } pause(); printf(子进程结束!\n); exit(0); } sleep(1); shmaddr=(char*)shmat(shmid,NULL,0); printf(请输入字符串:); scanf(%s,str); strcpy(shmaddr,str); shmdt(shmaddr); kill(pid,SIGUSR1); wait(); shmctl(shmid,IPC_RMID,NULL); } static

文档评论(0)

1亿VIP精品文档

相关文档