Linux-课程设计.docVIP

  • 18
  • 0
  • 约2.38千字
  • 约 14页
  • 2018-01-08 发布于江西
  • 举报
Linux-课程设计.doc

滨江学院 课程设计报告 题 目 Linux 课程设计 院 系 计 算 机 系 专 业 计算机科学与技术 学生姓名 学 号 2014年12月30日 目录 1. Shell编程题 2 1.1 求费波纳奇数列的前20项及总和。 2 1.2 实现自动 创建文件分别拷贝到各自相应的目录下。 3 1.3 shell编程判断文件是否存在,输出相应的结果 5 1.4 设计一个shell程序cuts 6 2. Linux下C语言程序设计—课程设计 8 2.1、Linux下用C语言进程实现 8 3. 实验总结 14 1. Shell编程题 1.1 求费波纳奇数列的前20项及总和。 Shall脚本代码截图: Linux下运行截图: 1.2 实现自动 创建文件分别拷贝到各自相应的目录下。 Shall脚本代码截图: 运行前目录截图: 运行后目录截图: 1.3 shell编程判断文件是否存在,输出相应的结果 Shall脚本代码截图: 运行截图 1.4 设计一个shell程序cuts 例如: $cuts 11 14 This is a test of cuts program (键盘输入) test (显示结果) 代码截图 运行截图 2. Linux下C语言程序设计—课程设计 2.1、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 void sign(int signnum) { int fd; char* shmaddr; if(signnum==SIGUSR1) { printf(子进程接收到SIGUSR1.\n); shmaddr=(char*)shmat(shmid,NULL,0); if((fd=open(testfile.txt,O_RDWR|O_CREAT|O_TRUNC))==-1) { printf

文档评论(0)

1亿VIP精品文档

相关文档