联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2019-04-22 09:52

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

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.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp