操作系统实验报告(1).docx

上传人:牧羊曲112 文档编号:3549716 上传时间:2023-03-13 格式:DOCX 页数:4 大小:37.68KB
返回 下载 相关 举报
操作系统实验报告(1).docx_第1页
第1页 / 共4页
操作系统实验报告(1).docx_第2页
第2页 / 共4页
操作系统实验报告(1).docx_第3页
第3页 / 共4页
操作系统实验报告(1).docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《操作系统实验报告(1).docx》由会员分享,可在线阅读,更多相关《操作系统实验报告(1).docx(4页珍藏版)》请在三一办公上搜索。

1、操作系统实验报告实验一 Linux/UNIX操作系统使用 命令解释程序 1)、目的 : 通过本实验熟悉UNIX或Linux操作系统及C语言。熟悉系统调用的编程能力,程序中允许使用库函数。 2)、内容: 利用C语言编写一个微型命令解释程序,接受并解释以下命令: dir 列当前目录 cop 文件1 文件2 拷贝文件 era文件名 删除文件 dis字符串 显示字符串 3)、要求: 进行命令合法性检查,若不合法,显示出错信息,等待重新输入; 命令前后有空格为合法命令。 4)、思路: 下面各题均有编程思路,目的是给大家一些提示、借鉴。同学们可不必拘泥与此,根据自己的理解和想法去编程。 用静态数组或二维数

2、组形式定义命令保留字表和shell命令字表。静态数组形式如下:static char * cst =dirend;static char * scwt =ls lexit; 输入命令字gets(string); 分离命令字strcspn;strncpy 比较命令字strcmp; 执行shell命令system; 以下是源程序代码: #include #include #include void apart(char input,char cmpstr,char output) /分离命令保留字及其后面部分 for(;istrlen(input);i+) char temp30=0; unsig

3、ned int j=0; unsigned int k; unsigned int m=0; while(inputi= )i+; /去掉命令字前的空格 unsigned int i=0; tempj=inputi; j+; for(k=0;kstrcspn(temp, );k+)cmpstrk=tempk; /分离命令,并判断命令后是否为空格, for(k=strcspn(temp, );kstrlen(temp);k+) /分离命令后面部分 outputm=tempk; m+; 如果不是空格,将分离出不正确的字符串 int main char *cwt =dir,cop,era,dis,e

4、nd; /命令保留字表 char *scwt =ls -l,cp,rm -f,echo,exit; /shell命令字表 char input30=0; /存放输入串 char cmpstr30=0; /存放分离后的命令保留字 char output30=0; /存放命名保留字后面的部分 char shellstr30=0; /shell命令 int i,j; fgets(input,30,stdin); if(input0!= ) printf(wrong commond!n); /检查命令前是否有空格 continue; printf(yxfxueyingxjtucs17#); while

5、(1) i=0; printf(dir cop era dis endn); printf(NOTICE:command must have the space in front and back of it!n ); printf(command list:n); apart(input,cmpstr,output); while(strcmp(cmpstr,cwti)!=0&(i=4)i+; if(i=4) /I等于4,则退出程序 strcpy(shellstr,scwti); strcat(shellstr,output); system(shellstr); break; else if(i4) strcpy(shellstr,scwti); strcat(shellstr,output); system(shellstr); / else printf(wrong command!n); / for(j=0;j=30;j+) / inputj=0; cmpstrj=0; outputj=0; shellstrj=0; 执行shell命令 否则,命令错误 清空字符串

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号