期末考核题目汇总

上传人:第*** 文档编号:31148416 上传时间:2018-02-05 格式:DOCX 页数:14 大小:296.70KB
返回 下载 相关 举报
期末考核题目汇总_第1页
第1页 / 共14页
期末考核题目汇总_第2页
第2页 / 共14页
期末考核题目汇总_第3页
第3页 / 共14页
期末考核题目汇总_第4页
第4页 / 共14页
期末考核题目汇总_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《期末考核题目汇总》由会员分享,可在线阅读,更多相关《期末考核题目汇总(14页珍藏版)》请在金锄头文库上搜索。

1、期末考核内容每人按照老师的要求,顺序或随即从下面 shell 编程部分和环境编程部分分别选择一题,然后在课堂上进行编程、演示运行结果,并回答老师至少三个问题。如不能回答,则不通过考核。通过考核后,应根据两个题目的题目分析、编程思想、相关知识、流程图、算法设计(如有) 、源代码及注释,完成实践课程报告,并打印后提交。老师根据平时考勤、演示结果、回答问题情况、实验报告情况打分。定于第九周周四上午进行考核。请各位同学做好准备。Shell 编程部分:1、 设计一个程序 cuts,它由标准输入读取数据,获取有第一个参数 n 和第二个参数 m 所限定范围的数据,n 和 m 都是整数 ,即从输入的字符串中抽

2、取第 n 个字符至第 m 个字符之间的所有字符(包括这两个字符)并显示出来。$ cuts 11 14This is a test of cuts program(回车)test(显示结果)P145 4.18#!/bin/bashread -p 请输入一段内容: TEXTread -p 请输入两个整数,中间用空格分开: num1 num2echo $TEXT | cut -b $num1-$num2 2/dev/null2、 利用 for 循环将当前目录下的 .c 文件移到指定的目录下,并按文件大小排序,显示移动后指定目录的内容。P144 4.12#!/bin/bashfor file in l

3、s -1 /root/a | grep .*.cmv /root/a/$file /root/bls -lS /root/b3、 编写一个 shell 脚本,求斐波那契奇数列的前 10 项及总和。P144 4.14#!/bin/bashi=1j=0for ( k=0; k100”;如果两个数字的和小于等于 100 并且大于10,就输出“x+y10”; 如果 xy,则求出 x 除以 y 的余数并输出“x mod y = ?(把计算的值代替问号)” ,否则求出 y 除以 x 的余数并输出“y mod x = ?”.P127 例 4.135、 编写一个 shell 脚本,并利用函数实现数列求和运算。

4、即主程序接受两个数字,分别作为数列头和数列尾,如果第一个数字不小于第二个数字则输出“wrong number”,否则将这两个数字传递给函数;函数把这两个数字中间的数字加起来求和,并输出。如:当输入 3 6 时,函数计算 3+4+5+6 的值并输出。#!/bin/shfun()sum=0for i in seq $1 $2dosum=expr $i + $sumdoneecho $sumecho Please input 2 number:read a bexpr $a + 0 1/dev/null 2&1if $? -ne 0 ;thenecho wrong numberexit 1;fiex

5、pr $b + 0 1/dev/null 2&1if $? -ne 0 ;thenecho wrong numberexit 1;fiif $a -ge $b ;thenecho wrong numberexit 1;fifun $a $b6、 编写特洛伊木马 shell 脚本。以文本方式登陆界面,接收用户输入的名字和密码。一旦用户在这种伪装界面登陆,就获取用户名和密码,并保存在指定的文件中。接着睡眠几秒,然后显示录入错误的信息,使用户以为输入有误。最后在调用真正的登陆程序,允许用户正常登陆。P107 例 4.67、 编写 shell 脚本,创建一个 5 个元素的数组,输出各个元素的值8、 编

6、写一个脚本,用于统计所指定文件的行数总数。输出结果为各个文件的名字+行数,以及总行数。如:当输入./脚本名 file1 file2,脚本计算 file1 和 file2 两个文件的总行数#!/bin/bash#statistics the raws of the files you inputusage()echo usage:please input = two filenamestotalline=0if $# -lt 2 ; thenusagefiwhile $# -ne 0 doline=cat $1 |wc -lecho $1:$linetotalline=$ $totalline+

7、$line shiftdoneecho -echo totalline: $totalline9、 编写一个 shell 脚本,根据键盘输入的值,给出对应的提示;输入A Z ,输出Uppercase Letter;输入a-z,输出 Lowercase Letter;输入0-9,输出 Digit;输入其他,输出 Punctuation, whitespace, or other#!/bin/bashexport LC_ALL=Cread awhile $a docase $a inA-Z) echo Uppercase Letter;a-z) echo Lowercase Letter;0-9)

8、 echo Digit;*) echo Punctuation, whitespace, or other;esacread adone10、 编写 shell 脚本,提示用户输入用户名,并判断此用户名是否存在与系统用户中P123 例 4.11Linux 环境编程部分:1、 编写一个程序,把一个文件的内容复制到另一个文件上,即实现简单的 copy 功能,要求:只用 open()/read()/write()/close()系统调用,程序的第一个参数为源文件,第二个参数为目的文件。P225 7.3#include #include #include #include #include #incl

9、ude #define BUF_SIZE 1024*8int main()int fds, fdd;char bufBUF_SIZE;size_t hasread = 0;fds = open(filea, O_RDONLY);fdd = open(fileb, O_WRONLY, O_CREAT);if(fds & fdd)while(hasread = read(fds, buf, sizeof(buf) 0)write(fdd, buf, hasread);close(fds); close(fdd);2、 编写一个程序它利用 fork()创建一个子进程;父进程打开一个文件,父子进程都向

10、文件中写入信息(利用 write) ,表明是在那个进程中;每个进程都打印两个进程的 ID号。最后父进程执行 wait() 。P225 7.5#include#include#include#include#include#includeint main()pid_t pid;int fd;char *buf1=(char *)malloc(20);char *buf2=(char *)malloc(20);strcpy(buf1,this is child process:);strcpy(buf2,this is parent process:);if(fd=open(file,O_CREA

11、T|O_RDWR)#include#include#include#include#includeint main()pid_t pid;int fd;char *buf1=(char *)malloc(20);char *buf2=(char *)malloc(20);strcpy(buf1,this is child process:);strcpy(buf2,this is parent process:);if(fd=open(file,O_CREAT|O_RDWR)#include #include #include #include #include int main() int

12、fd = -1; fd = open(zhidao_561804018.dat, O_CREAT | O_TRUNC | O_RDWR, 0666);if (fd 0) close(fd);fd = -1; return 0;6、 首先建立一个守护进程,然后让该守护进程每隔 10s 在/tmp/dameon.log 中写入一句话#include #include #include #include #include #include #include #define MAXFILE 65535int main(void) pid_t pc;int i,fd,len;char *buf=This

13、 is a Dameonn;len=strlen(buf);pc=fork();if(pc0)exit(0);setsid();chdir(/);umask(0);for(i=0;i#include #include void my_op(int);main()sigset_t new_mask;struct sigaction act;sigemptyset(act.sa_flags=0;act.sa_handler=my_op;if(sigaction(SIGINT,&act,NULL) /注册信号 SIGINT 处理函数为 my_opprintf(install signal SIGIN

14、T errorn);if(sigaction(SIGQUIT,&act,NULL) /注册信号 SIGQUIT 处理函数为 my_opprintf(install signal SIGQUIT errorn);printf(please send signal: kill -s %d %dn,SIGQUIT, getpid();sigemptyset( if(sigprocmask(0, NULL,&new_mask) 0) /查询当前进程被挂起的信号存入new_mask 中,/可用 sigpending(&new_mask)代替printf(get pending mask errorn);sigaddset( /将信号 SIGQUIT,添加到信号集 new_mask 中,/也就是在原有的信号掩码中加入信号 SIGQUIT。sigsuspend( /将当前的信号掩码替换成 new_mask,/也就是把信号 SIGQUIT 给阻塞后,当前进程挂起。/必须等待除了未阻塞的信号到来才恢复成原来的信号掩码exit(0);void my_op(int signum)if ( signum = SIGINT )printf(SIGINTn);else if ( signum = SIGQUIT )printf(SIGQUITn);return;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号