资源简介
一个简单的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版本
- 下一篇:数字信号处理的函数库
相关资源
- C++中头文件与源文件的作用详解
- 基于mfc的多线程文件传输
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 计算机二级C语言上机填空,改错,编
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- C语言进阶——嵌入式系统高级C语言编
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 《LINUX C编程从初学到精通》光盘源码
- 嵌入式QtC++编程课件
- 嵌入式c编程语言入门与深入.pdf58199
- C语言模块化编程(我见过最好的)
- 颜色识别形状识别STM103嵌入式代码
- 汽车电子编程规范(Unlock-MISRA C 2012)
评论
共有 条评论