资源简介
一个简单的shell实现,包括了shell所以的基本功能,容易理解,适合初学者下载学习。
代码片段和文件信息
/* syscalls.c
* Nachos system call interface. These are the enveloped Nachos kernel
* operations that can be invoked from user programs.
* Each NachOS system call is translated to an apropriate LIBC call.
* Hopefully this works on MacOS X *nix and Windows
*/
#include “nachos_syscall.h“
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#ifdef HAVE_CONFIG_H
#include “config.h“
#endif
#define SHELL “/bin/sh“
/*
* The system call interface. These are the operations the Nachos
* kernel needs to support to be able to run user programs.
*/
/* Stop Nachos and print out performance stats */
void Halt()
{
Exit(0);
}
/*
* Add the two operants and return the result
*/
int Add(int op1 int op2)
{
return op1 + op2;
}
/* This user program is done (status = 0 means exited normally). */
void Exit(int status)
{
exit(status);
}
/* Address space control operations: Exit Exec Execv and Join */
/* Run the specified executable with no args */
/* This can be implemented as a call to ExecV.
*/
SpaceId Exec(char* exec_name)
{
pid_t child;
child = vfork();
if(child == 0)
{
execl (SHELL SHELL “-c“ exec_name NULL);
_exit (EXIT_FAILURE);
}
else if(child < 0)
return EPERM;
return (SpaceId) child;
}
/*
* Run the executable stored in the Nachos file “argv[0]“ with
* parameters stored in argv[1..argc-1] and return the
* address space identifier
* For this the incoming string has to be seperated by replacing “ “
* with “\n“ and building the appropriate pointer structure argv.
*/
SpaceId ExecV(int argc char* argv[])
{
pid_t child;
child = vfork();
if(child == 0){
execl (SHELL SHELL “-c“ argv NULL);
_exit (EXIT_FAILURE);
}
else if(child < 0)
return EPERM;
return (SpaceId) child;
}
/* Only return once the user program “id“ has finished.
* Return the exit status.
*/
int Join(SpaceId id)
{
return waitpid((pid_t) id (int*) 0 0);
}
/* File system operations: Create Remove Open Read Write Close
* These functions are patterned after UNIX -- files represent
* both files *and* hardware I/O devices.
*
* Note that the Nachos file system has a stub implementation which
* can be used to support these system calls if the regular Nachos
* file system has not been implemented.
*/
/* when an address space starts up it has two open files representing
* keyboard input and display output (in UNIX terms stdin and stdout).
* Read and Write can be used directly on these without first opening
* the console device.
*/
/* Create a Nachos file with name “name“ */
/* Note: Create does not
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 535 2008-04-27 23:42 shell\shell.dsw
文件 33792 2008-04-27 23:49 shell\shell.ncb
文件 33792 2008-04-27 23:47 shell\Debug\vc60.idb
文件 45056 2008-04-27 23:47 shell\Debug\vc60.pdb
文件 167636 2008-04-27 23:46 shell\Debug\shell.pch
文件 3083 2008-04-27 23:46 shell\Debug\shell.obj
文件 0 2008-04-27 23:45 shell\nachos_syscall.cpp
文件 4929 2008-04-27 23:46 shell\nachos_syscall.h
文件 726 2008-04-27 23:46 shell\shell.c
文件 892 2008-04-27 23:47 shell\shell.plg
文件 7325 2008-04-27 23:49 shell\nachos_syscall.c
文件 48640 2008-04-27 23:49 shell\shell.opt
文件 4408 2008-04-27 23:49 shell\shell.dsp
目录 0 2008-04-27 23:42 shell\Debug
目录 0 2008-04-27 23:42 shell
----------- --------- ---------- ----- ----
350814 15
- 上一篇:socket通信MFC版本
- 下一篇:数字信号处理的函数库
相关资源
- VS2010 C++配色方案 主题
- Qt-C++实现文件浏览器
- BASIC语言编程初学者手册
- C语言socket编程指南(讲解+)
- c++ MFC实现文件合成器功能,实现多种
- 图书管理系统C++65062
- c++ 记事本 源码
- c++头文件大全,很全哦,
- PCA和KPCA的Matlab和C++程序
- MFC中的多线程同步
- 山东科技大学C++数据库课程设计源代
- c++做的仪表盘非常逼真哦
- c++ 连接sql server 数据库代码
- 缓冲池的模拟(C++)
- c++版的连连看解释很详细
- 激光雷达数据读取、显示、分割、直
- 旅游管理系统 C++ SQL
- Exceptional C++(中文版).侯捷-侯老师的
- C++实现获取win7系统端口号IP状态和P
- C++编程规范_101条规则、准则与最佳实
- C++学校人员信息管理系统课程设计.
- 学生作业完成情况管理系统C++含报告
- mysql封装.zip
- 诊所信息管理系统.cpp
- 六子棋游戏即二打一棋C++源程序
- C++实现哈夫曼树及哈夫曼编码.rar
- C++ primer plus第五版学习笔记
- 判断一个代数系统的封闭性、结合律
- C++(CS起源GDI透视自瞄)+代码全写了
- 数据结构——迷宫问题
评论
共有 条评论