资源简介
《操作系统—精髓与设计原理》一书中myshell编程项目,代码写得很清晰,纠错能力很强大,实现了基本的内部命令:cd、dir、help、echo、environ等,以及实现文件重定向、后台处理等功能。附有实验报告。

代码片段和文件信息
/* 操作系统练习1: myshell.c
姓名: 杨富强
学院:通信工程
学号:01051312
在Ubuntu7.10和cygwin下已经测试通过
*/
#include “myshell.h“
int main (int argc char *argv[])
{
char buf [MAX_BUFFER] pwd [MAX_ARGS]; // line buffer
char shell_path[MAX_ARGS]=“shell=“;
char readme_path[MAX_ARGS]=“readme_path=“;
char newpath[MAX_ARGS*1000];
int len;
strcpy(newpathgetenv(“PATH“));
strcat(newpath“:“);
if(strcmp(argv[0]“./myshell“)&&strcmp(argv[0]“myshell“))
{
len=strlen(argv[0]);
while(len&&argv[0][len]!=‘/‘) len-- ;
argv[0][len]=‘\0‘;
strcpy(pwdargv[0]);
get_fullpath(pwd argv[0]);
printf(“%s\n“pwd);
}
else strcpy(pwd getenv(“PWD“));
strcat(newpathpwd); // strcat(newpathgetenv(“PWD“));
setenv(“PATH“newpath1);// add the current working directory in the “PATH“ environment variable to search for the filename specified.
strcat(shell_pathpwd); // strcat(shell_path getenv(“PWD“));
strcat(shell_path“/myshell“);
putenv( shell_path); //add the working directory of myshell in the environment variables
strcat(readme_path pwd); // strcat(readme_path getenv(“PWD“));//
strcat(readme_path“/readme“);
putenv(readme_path); // add the filepath of the file “readme“ in the environment variables see function my_help( ) !
if(argc>1) // 也许用户直接在终端输入 ./myshell a.bat >c.txt
{
strcpy(buf“myshell “);
int i;
for(i=1;i {
strcat(bufargv[i]);
strcat(buf“ “);
}
Execute(buf);// execute this command, 执行这个批处理命令
}
else // 如果用户在终端输入 ./myshell
{
my_clear( );
fprintf(stderr “Welcome Enter myshell!\nType \“help\“ to see the help information.\n“);
my_shell(stdinNULLNULL);
}
return 0 ;
} // end function “main“
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 188 2008-06-17 12:39 myshell_for_linux\makefile
文件 2118 2008-06-17 12:39 myshell_for_linux\myshell.c
文件 2265 2008-06-17 12:39 myshell_for_linux\myshell.h
文件 11840 2008-06-17 12:39 myshell_for_linux\readme
文件 40643 2008-06-17 12:39 myshell_for_linux\utility.c
文件 371200 2009-04-27 14:29 操作系统实验报告.doc
目录 0 2010-11-02 23:24 myshell_for_linux
----------- --------- ---------- ----- ----
428254 7
- 上一篇:WEBRTC多人视频通话
- 下一篇:ubuntu USB驱动
相关资源
- 升腾Win终端系统升级方法新版.doc
- Uninstall_Cortana_WINCLIENT.CN.rar
- STM32基于rt_thread操作系统的SDHC卡文件
- 操作系统 LRU算法 实验报告 及 程序代
- [免费]车载CE6.0操作系统
- 分页系统模拟实验 操作系统 课程设
- 模拟段页式虚拟存储管理中地址转换
- 操作系统实验——虚存管理实验
- 广工操作系统实验
- 广东工业大学操作系统实验四文件系
- Bochs入门教程[操作系统第一步]
- 操作系统课程设计完整版
- 磁盘调度算法的模拟实现及对比
- 模拟一个文件管理系统
- 二级文件系统(操作系统)
- uCOS编译环境建立 BC45 TASM
- Linux 操作系统实验(全)
- 操作系统实验综合设计【附代码】
- 操作系统共享内存实验
- 操作系统循环首次适应算法
- 操作系统课程设计实现可变分区存储
- 基于GTK的Linux环境下的简易任务管理器
- 操作系统课程设计 二级文件管理系统
- 加快Windows XP操作系统开机速度
- 操作系统教程课后答案华中科技大学
- 51单片机中使用ucos ii的优缺点转
- 51单片机中使用ucos ii的优缺点
- 嵌入式实时操作系统ucos-II 第二版 源
- 计算机操作系统课后_汤小丹_第四版
- 计算机操作系统(第四版)汤小丹课
评论
共有 条评论