xv6 shell
来源:互联网 发布:淘宝上刷q币是真的吗 编辑:程序博客网 时间:2024/06/05 00:59
1、在home下新建shell.c文件,拷贝原有代码,并修改runcmd部分:
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"); // system(ecmd->argv[0]); // Your code here ... // execl("/bin/sh", "sh", "-c", ecmd->argv[0], (char *)0); execvp(ecmd->argv[0],ecmd->argv); break; case '>': case '<': rcmd = (struct redircmd*)cmd; FILE *stream; if(rcmd->fd == 1) stream = freopen(rcmd->file,"w",stdout); else freopen(rcmd->file,"r",stdin); if(stream == NULL) fprintf(stderr,"errorredirecting\n"); else{ runcmd(rcmd->cmd); fclose(stream); } break; case '|': pcmd = (struct pipecmd*)cmd; int p[2]; if(pipe(p) < 0) fprintf(stderr,"pipe not implemented\n"); if(pipe(p) == 0){ if(fork1() == 0){ close(1); dup2(p[1],1); close(p[0]); runcmd(pcmd->left); } else{ close(0); dup2(p[0],0); close(p[1]); runcmd(pcmd->right); } } // Your code here ... break; } exit(0);}
2、在home下新建t.sh文件,输入如下代码:
ls > ycat < y | sort | uniq | wc > y1cat y1ls | sort | uniq | wcrm y
3、运行结果如下图所示:
阅读全文
0 0
- xv6 shell
- xv6-lab(1)--shell
- xv6 Shell & OS organization
- 【xv6学习之HW1】shell
- Implement a Shell by yourself -- MIT xv6 shell
- xv6 locking
- xv6 barrier
- xv6 crash
- XV6内存布局
- xv6内存布局详解
- XV6 进程调度分析
- xv6自旋锁
- xv6文件系统详解
- xv6的main.c
- xv6的中断分析
- The bootloader of xv6
- ubuntu运行xv6
- 运行 XV6 记录
- 环信SDK 踩坑记webIM篇(二)
- 记录一些常用的utils方法3
- JAVA的23种设计模式---备忘录模式(一)
- 关于初级程序员职场如何提升技能的几点建议?
- Android进入APP判断引导页是否显示.
- xv6 shell
- Struts2:上传单个文件
- 简单实现UGUI拖拽功能
- 从上往下打印二叉树
- 深入理解 Android 中的 Matrix
- javaWeb服务详解(含源代码,测试通过,注释) ——applicationContext-Service.xml
- JDK中设计模式
- Struts2 上传文件更改名字
- Ubuntu 14.04 LTS 安装 Mac 主题