资源简介
天津大学计算机科学与技术专业,大三上学期,操作系统原理实验报告,文件管理、主存管理等。

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
// Simplifed xv6 shell.
#define MAXARGS 10
// All commands have at least a type. Have looked at the type the code
// typically casts the *cmd to some specific cmd type.
struct cmd {
int type; // ‘ ‘ (exec) | (pipe) ‘<‘ or ‘>‘ for redirection
};
struct execcmd {
int type; // ‘ ‘
char *argv[MAXARGS]; // arguments to the command to be exec-ed
};
struct redircmd {
int type; // < or >
struct cmd *cmd; // the command to be run (e.g. an execcmd)
char *file; // the input/output file
int mode; // the mode to open the file with
int fd; // the file descriptor number to use for the file
};
struct pipecmd {
int type; // |
struct cmd *left; // left side of pipe
struct cmd *right; // right side of pipe
};
int fork1(void); // Fork but exits on failure.
struct cmd *parsecmd(char*);
//运行cmd,Never returns.
void runcmd(struct cmd *cmd)
{
int p[2] r;
struct execcmd *ecmd;
struct pipecmd *pcmd;
struct redircmd *rcmd;
if(cmd == 0)
{
exit(0);
}
switch(cmd->type)
{
default:
fprintf(stderr “unknown runcmd\n“);
exit(-1);
case ‘ ‘:
ecmd = (struct execcmd*)cmd;
if(ecmd->argv[0] == 0)
{
exit(0);
}
//fprintf(stderr “exec not implemented\n“);
// Your code here ...
//在当前目录下搜索执行文件失败
if(execv(ecmd->argv[0] ecmd->argv) == -1)
{
//更换为/bin/目录
char cmdPath[30] = “/bin/“;
//连接字符串/bin/与之前的目录
strcat(cmdPath ecmd -> argv[0]);
//在/bin/目录下搜索执行文件失败
if(execv(cmdPath ecmd->argv) == -1)
{
//更换为/usr/bin/目录
char cmdPath2[30] = “/usr/bin/“;
//连接字符串/usr/bin/与最初的目录
strcat(cmdPath2 ecmd -> argv[0]);
//更换为/usr/bin/目录搜索执行文件失败
if(execv(cmdPath2 ecmd->argv) == -1)
{
//执行文件不存在,结束当前进程
fprintf(stderr “Can‘t found file: %s%d\n“ ecmd -> argv[0] __LINE__);
exit(0);
}
}
}
break;
/*
//如果有权限访问文件且文件存在
if(access(ecmd->argv[0]F_OK) == 0)
{
//找到可执行文件
execv(ecmd->argv[0] ecmd->argv);
}
else
{
//有权限访问文件,将当前的工作目录改变成/bin/目录搜索失败
if(chdir(“/bin/“) < 0)
{
//文件不存在,结束当前进程
printf(“Can‘t change directory %d\n“ __LINE__);
exit(0);
}
//有权限访问文件,在/bin/搜索可执行文件成功
execv(ecmd->argv[0] ecmd->argv);
}
//既无权限,执行文件又不存在,结束当前进程
fprintf(stderr “Can‘t find file: %s %d\n“ ecmd->argv[0] __LINE__);
break;
*/
case ‘>‘:
case ‘<‘:
rcmd = (struct redircmd*)cmd;
//fprintf(stderr “redir not implemented\n“);
// Your code here ...
//‘<‘为0,‘>’为1
close(rcmd->fd);
//open()函数,对产生的新文件赋
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-09-17 20:06 lab1\
文件 10827 2017-10-19 22:15 lab1\lab1.c
目录 0 2018-09-17 20:06 lab2\
文件 1569 2017-10-31 21:46 lab2\lab2.c
文件 1652440 2018-09-17 20:11 主存管理实验报告.doc
文件 2084546 2018-09-17 20:11 文件管理实验报告.doc
相关资源
- 数学建模实验报告(八个全)
- 数字逻辑与数字系统实验报告
- 多媒体综合设计报告(附作品)
- ubuntu9.10 可加载内核模块和字符设备驱
- 操作系统 LRU算法 实验报告 及 程序代
- 迈克尔逊干涉仪的调整与使用实验报
- 利用启发式搜索解决八数码难题程序
- 比较两个字符串大小汇编语言源代码
- linux实验报告及心得体会
- 数据结构实验-魔王语言-源码加实验报
- 2FSK2PSK信号产生器实验实验报告
- 软件工程课程设计【网上选课系统】
- 表达式求值C 代码(附实验报告)
- 湖南大学操作系统实验报告
- 哈夫曼树编码和译码实验报告+运行视
- 哈工大威海-嵌入式实验报告答案
- 银行储蓄系统实验报告
- 操作系统实验报告哲学家就餐问题、
- 北航研究生计网实验报告.rar
- PS作业 实验报告 11
- 数据结构算术表达式求值实验报告
- 哈工大威海编译原理实验报告和源代
- 哈工大威海-编译原理实验报告和源码
- 软件项目管理实验报告
- 数字图像处理课程设计 实验报告
- 河北工业大学编译原理实验代码及实
- 东北大学软件学院编译方法两次实验
- Linux 进程控制与进程互斥附实验报告
- 电力系统潮流计算(高斯-赛德尔法)
- 离散数学实验报告4——图的应
评论
共有 条评论