为毛《操作系统》的作业是写个Shell!
嗯,大学二年级的课程,要求写一个跨平台的shell,就像windows下面的cmd和linux下面的terminal,后面特别注明要写个在UNIX系统上能运行的。光是需求就两页A4纸啊(有点夸张,就是书本有正反两页),要求如下:
1、cd <directory>改变当前目录
2、clr清屏
3、dir <directory>列出目录下的文件夹和文件
4、environ 列出系统变量
5、echo 回显 多个空格和tab必须消除为一个
6、help 显示帮助(display the user manual using the more filter 后半句话没看懂)
7、pause ---pause operation of the shell until 'Enter' is pressed
8、quit 退出shell(汗,这个是最简单的)
9、没看懂:the shell environment should contain shell=<pathname>/myshell where <pathname>/myshell is the full path for shell executable(not hardwired path back to your directory,but the one from which it was executed)
还有要求所有在shell中运行的程序都作为shell的子进程,支持批处理文件的运行,支持IO重定向(stdin stdout stderr到myshell),支持后台进程(就像linux中运行一个后台进程需要在命令后面加一个&一样),需要提示当前目录地址(像c:\>这样)
我在这也不求谁能帮忙写这个,就是感慨一下,国外的学生都是怎样被训练的(这是国外原版教材)。我个人觉得,我能把前面的命令识别不写成if else if else if而是用个hash表保存命令字符串和函数地址就已经不错了,原来C和C++课程天天教怎么算素数,突然难度提高到这个地步。我们同学说网上有现成的源代码,但是我不太想直接抄(逼急了那就算了)嘿嘿~
还有,后面要求用gcc+MAKEFILE编译~
[解决办法]
表示操作系统书后半本还是新地……
[解决办法]
这样多好啊。。能学到真东西。我们上操作系统的时候就做个调度的演示系统,半天就搞定了一点意思都没有。多学学*INX环境编程对以后找工作肯定有帮助的。
楼主加油!~~
[解决办法]
这样的学校和老师越来越少了,要珍惜。
学编程,不动手是不行的
[解决办法]
这样才能进步嘛,平时的作业都是过家家,走出校门以后怎么在社会上立足
[解决办法]
抄别人代码 也是种技能
可以看下 glibc 早的版本 代码好读
[解决办法]
想想我们学操作系统的时候,做实验时老师已经把程序写好了,我们只是去电脑上把程序跑一遍,唉。
[解决办法]
- C/C++ code
#include <unistd.h>#include <stdio.h>#include <sys/types.h>int main (void){ char str[100]; pid_t pid; int state; printf("%%"); while(fgets(str,100,stdin)!=NULL){ if(str[strlen(str)-1]=='\n'){ str[strlen(str)-1]=0; } if(pid=fork()==0){ execlp(str,str,(char *)0); }else{ waitpid(pid,&state,0); printf("%%"); } } /* pid_t pid; pid=fork(); if (pid < 0) printf("error in fork!"); else if (pid == 0) printf("i am the child process, my process id is %dn",getpid()); else printf("i am the parent process, my process id is %dn",getpid()); printf("\n%d\n",pid);*/}
[解决办法]
清屏是cls不是clr