CMSC 216 Exercise #5
CMSC 216 Exercise #5 Spring 2019
Shell Jr (”Shellito”) Due: Tue Apr 23, 2019, 11:30PM
1 Objectives
To practice fork() and exec by implementing a very simple shell.
2 Overview
The first thing you need to do is to copy the directory shelljr we have left in the grace cluster under the exercises
directory. Remember that you need that folder as it contains the .submit file that allows you to submit.
3 Specifications
For this exercise you will implement a very simpliflied shell. A shell is a C program that executes commands
by forking itself and using exec. We have been using tcsh, but there are other shells like ksh, sh, bash, etc. The
name of our shell is shell jr .
Unlike other assignments for this course, you can work together with other classmates, but you may NOT
exchange any code.
4 Shell Jr Functionality
Your shell will have a loop that reads command lines and process them. The prompt for your shell will be
”shell jr: ”. The commands your shell must handle are:
1. exit - When the user enters the exit command the shell will stop executing by calling exit(). Before
executing exit, the shell will print the message ”See you”.
2. hastalavista - Has the same functionality as exit.
3. cd - This command changes the current directory. You can assume the user will always provide a directory
as an argument.
4. A command with a maximum of one argument (e.g., wc location.txt). That means your shell should be
able to handle commands like pwd, date or wc location.txt .
5 Requirements
代做CMSC 216作业、代写Shellito留学生作业、C/C++语言作业代写
1. You must NOT use an exec* function to implement the functionality associated with the commands
exit, hastalavista, and cd. For other commands, you must create a child (via fork()) and use execvp() to
execute the command.
2. If the user provides an invalid command, the message ”Failed to execute ” followed by the command
name should be printed. In this case the child will exit returning the error code EX OSERR. Use printf
to display the message and flush the output buffer (e.g., fflush(stdout)). Note that the shell is not terminated
by executing an invalid command.
3. You don’t need to handle the case where the user just types enter (you can assume the user will always
provide a command).
4. Make sure you use printf to print the shell prompt and that you flush the buffer.
5. It is your responsibility to verify that your program generates the expected results in the submit server.
1
6. You must use execvp (and no other exec* system call).
7. Your code must be written in the file shell jr.c.
8. You may not use dup2, read, write, nor pipes.
9. You may not use system() in order to execute commands.
10. You can assume a line of input will have a maximum of 1024 characters.
11. Provide a makefile that builds an executable called shell jr. Name the target that builds the executable
shell jr . Feel free to add any other targets you need.
12. All your C programs in this course should be written using the compiler gcc, with the options defined
in the gcc aliases info.txt file. This file can be found in the info folder of the public grace account.
13. Your program should be written using good programming style as defined at
http://www.cs.umd.edu/~nelson/classes/resources/cstyleguide/
14. Common error: If you get the submit server message ”Execution error, exit code 126” execute ”make
clean” before submitting your code.
15. Common error: To forget to return the correct value (e.g., 0) in your code.
16. Your C program representing your shell does not take command line arguments. That is, the main
function is defined as:
int main() { }
17. When you see that execvp relies on argv that means it uses an array of strings (argv is not the parameter
associated with command line arguments). Just initialize argv with an array of strings and pass it to
execvp.
18. Your shell should exit when end of file is seen. This explains why public tests do not have exit nor
hastalvista as the last command.
19. ShellJr exercise relies on Standard I/O, NOT unix I/O.
20. ShellJr takes a maximum of two arguments (e.g., wc location.txt). You can ignore any other values
provided after the second argument. For example, if someone enters wc location.txt bla bla will be
ignored and the command will be processed successfully.
21. For exit and hastalavista you can ignore any values provided after the command (just exit the shell).
22. For cd you can ignore any values provided after the directory name. For example, cd /tmp bla will
change the current directory to /tmp.
23. If an invalid directory is provided to the cd command, your shell should print an error message similar
to:
"Cannot change to directory <DIRECTORY_HERE>"
24. Do not use signals.
2
6 How to Start
You should start by creating a loop that reads lines and displays them. Then you should begin to process
each command (starting with the exit and cd commands). You are free to process each line any way you
want, however, reading a whole line using fgets and then processing the line using sscanf could make things
simpler. Keep in mind that if sscanf cannot read a value into a string variable, it will not change the variable.
This could help you identify when a command has an argument or not.
7 Submitting your assignment
1. In the assignment directory execute the command submit.
2. Your assignment must be electronically submitted by the date and time above to avoid losing credit. See
the course syllabus for details.
8 Grading Criteria
Your assignment grade will be determined with the following weights:
Results of public tests 28%
Results of release tests 72%
9 Academic integrity statement
Please carefully read the academic honesty section of the course syllabus. Any evidence of impermissible
cooperation on assignments, use of disallowed materials or resources, or unauthorized use of computer accounts,
will be submitted to the Student Honor Council, which could result in an XF for the course, or suspension
or expulsion from the University. Be sure you understand what you are and what you are not permitted
to do in regards to academic integrity when it comes to assignments. These policies apply to all students, and
the Student Honor Council does not consider lack of knowledge of the policies to be a defense for violating
them. Full information is found in the course syllabus– please review it at this time.
因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
微信:codinghelp
CMSC 216 Exercise #5的更多相关文章
- Android Studio Error:CreateProcess error=216
Error:CreateProcess error=216, This version of %1 is not compatible with the version of Windows you' ...
- MIT 6.828 JOS学习笔记12 Exercise 1.9
Lab 1中Exercise 9的解答报告 Exercise 1.9: 判断一下操作系统内核是从哪条指令开始初始化它的堆栈空间的,以及这个堆栈坐落在内存的哪个地方?内核是如何给它的堆栈保留一块内存空间 ...
- MIT 6.828 JOS学习笔记13 Exercise 1.10
Lab 1 Exercise 10 为了能够更好的了解在x86上的C程序调用过程的细节,我们首先找到在obj/kern/kern.asm中test_backtrace子程序的地址, 设置断点,并且探讨 ...
- MIT 6.828 JOS学习笔记11 Exercise 1.8
Exercise 1.8 我们丢弃了一小部分代码---即当我们在printf中指定输出"%o"格式的字符串,即八进制格式的代码.尝试去完成这部分程序. 解答: 在这个练 ...
- MIT 6.828 JOS学习笔记8. Exercise 1.4
Lab 1 Exercise 4 阅读关于C语言的指针部分的知识.最好的参考书自然是"The C Programming Language". 阅读5.1到5.5节.然后下载poi ...
- MIT 6.828 JOS学习笔记9. Exercise 1.5
Lab 1 Exercise 5 再一次追踪一下boot loader的一开始的几句指令,找到第一条满足如下条件的指令处: 当我修改了boot loader的链接地址,这个指令就会出现错误. 找到这样 ...
- MIT 6.828 JOS学习笔记5. Exercise 1.3
Lab 1 Exercise 3 设置一个断点在地址0x7c00处,这是boot sector被加载的位置.然后让程序继续运行直到这个断点.跟踪/boot/boot.S文件的每一条指令,同时使用boo ...
- MIT 6.828 JOS学习笔记3. Exercise 1.2
这篇博文是对Lab 1中的Exercise 2的解答~ Lab 1 Exercise 2: 使用GDB的'si'命令,去追踪ROM BIOS几条指令,并且试图去猜测,它是在做什么.但是不需要把每个细节 ...
- Stanford coursera Andrew Ng 机器学习课程编程作业(Exercise 2)及总结
Exercise 1:Linear Regression---实现一个线性回归 关于如何实现一个线性回归,请参考:http://www.cnblogs.com/hapjin/p/6079012.htm ...
随机推荐
- 简单SQL注入
既然是简单的,估计也就是''字符型把,输入'or'1 以下是输出结果,or没被过滤,单引号也没有 呢么用union联合注入试试,提交了'-1 union/**/select 1 and '1,发现回显 ...
- Easyui datalist 使用记录
仅简单记录下,资料相对比较少 官方给了一个很简单的例子,没啥用处,文档:http://www.jeasyui.com/documentation/datalist.php 学习要点: 1.追加行 $( ...
- jQuery的选择器中的通配符[id^='code']或[name^='code']及jquery选择器总结
1.选择器 (1)通配符: $("input[id^='code']");//id属性以code开始的所有input标签 $("input[id$='code']&quo ...
- UOJ#195. 【ZJOI2016】大♂森林 LCT
原文链接https://www.cnblogs.com/zhouzhendong/p/UOJ195.html 题解 首先询问都可以放到最后处理. 对于操作,我们把它差分一下离线下来. 现在的问题就是从 ...
- Scala模式匹配| 隐式转换
1. 模式匹配 Scala中的模式匹配类似于Java中的switch语法,但是更加强大.模式匹配语法中,采用match关键字声明,每个分支采用case关键字进行声明,当需要匹配时,会从第一个case分 ...
- Codeforces 730 J.Bottles (01背包)
<题目链接> 题目大意: 有n个瓶子,各有水量和容量.现在要将这写瓶子里的水存入最少的瓶子里.问你最少需要的瓶子数?在保证瓶子数最少的情况下,要求转移的水量最少. 解题分析:首先,最少的瓶 ...
- C# .net 中 Timeout 的处理及遇到的问题
C# 中 Timeout 的处理 前言 最近在项目中要实现一个功能,是关于 Timeout 的,主要是要在要在 TCP 连接建立的时间 和 整个请求完成的时间,在这两个时间层面上,如果超出了设置的时间 ...
- Django学习笔记二
Django学习笔记二 模型类,字段,选项,查询,关联,聚合函数,管理器, 一 字段属性和选项 1.1 模型类属性命名限制 1)不能是python的保留关键字. 2)不允许使用连续的下划线,这是由dj ...
- HDU.4903.The only survival(组合 计数)
题目链接 惊了 \(Description\) 给定\(n,k,L\),表示,有一张\(n\)个点的无向完全图,每条边的边权在\([1,L]\)之间.求有多少张无向完全图满足,\(1\)到\(n\)的 ...
- Android系统API综述
下述能够找到Android开发源代码: 1. http://grepcode.com/project/repository.grepcode.com/java/ext/com.google.andro ...