” 辅导CO004留学生程序、Operating Systems程序 写作Project 1 – A simple shellCO004 Projects on Operating SystemsMarch 27, 20201 Objective Understanding how a shell works. Increasing experience with system calls. Learning about redirection and pipes. Learning about job controls.2 IntroductionThis project will help you understand Unix shell and system calls. After completing theproject, you should be familiar with programming with LINUX system calls.Essentially, a shell should prompt the user for input. The prompt usually consists of thecurrent directory. After the user inputs the command line, the shell parses it, and executeseach part of the command line according to the specification.You should write a simple LINUX shell. The shell should read a line of input, processit, and execute the commands. In particular, you are required to implement: (i) handlingbuilt-in commands (which are to be handled by the shell itself) and external programs; (ii)handling of important shell constructs (such are pipes, redirection, etc.); (iii) handing jobs(such as put a foreground job to background and put a background job to foreground).This is a group project. You can form a group with at most 3 members. You shalllearn how to solve a middle-level problem with collaboration with your partners and learnhow to manage your time under a tight schedule.3 Specification3.1 IntroductionThe shell program that you are going to implement is a simpler version than the ones thatyou use in Unix or Linux system. For simplicity, we name the shell that you are going toimplement as the OS shell.1. When the OS shell first starts, the program should be in the state Waiting for inputcommand line. The OS shell should show the following prompt:$ _1There should be one and only one white space after the dollar sign.2. When the user types in a command followed by a carriage return (or the enter key),e.g.,$ ls | moreThen, the received input will be processed by the Command line interpreter of theOS shell. If the command line interpreter finds that the input command line agrees with thepre-defined syntax, which will be defined in Section 3.2, then the OS shell shouldinvoke the commands specified by the input command line. Else, the input command line will not be executed and the OS shell gives the errormessages to the user Commands not found!, and then waits for another inputcommand line, i.e., going back to the state Waiting for input command line.3.2 Command line interpreterThe input command line is a character string. The OS shell should read in the input commandline from the standard input stream (stdin in C) of the OS shell. To ease your implementation,there are assumptions imposed on the input command line:Assumptions 辅导CO004留学生作业、Operating Systems作业 写作1. An input command line has a maximum length of 80 characters.2. An input command line ends with a carriage return character \n.3. There is neither leading nor trailing space characters in the input command line.4. A token is a series of characters without any space characters. Each token (or word) inthe input command line is separated by at least one space character.3.2.1 Internal commandsThe OS Shell should support the following internal commands: Any other build-in commands, e.g., ls, mkdir, who, whoami, cp, mv, rm, rmdir, cal,chmod, pwd, etc, where I do not list all the commands, which does not mean that theOS shell cannot process them. In fact, the OS shell should support all the commands. exit terminates your OS Shell. go ARG changes the current working directory to the directory supplied as ARG, where ARGcab be any valid directory. If there is no argument, you should print an error message. pid displays the pids of the 5 recent child processes,$ pid[5] 5022[4] 4087[3] 3427[2] 3215[1] 29872 history The OS shell can display all the historical commands that have been executedbefore (the maximum history record is 5000). Note that the OS shell should be able to resolve the parameters of these commands aswell. For example, ls al.3.2.2 External programsThe OS shell should be able to execute any other external programs as well. For example,an executable program hello generated by gcc compiler can run in the OS shell correctly,e.g., your run ./hello in the OS shell.3.3 Shell constructs (I/O Redirection and Pipes) and multiple commandsThere are certain constructs the OS shell needs to support.redirection – standard input is redirected using ARG. This means that command receiveseverything written in the file ARG, as it would be typed on the keyboard. Standard output isredirected by using ARG. You do not need to care about standard error.pipes – two (or more) commands can be connected together using the syntax COMMAND1 |COMMAND2. This connects the output of COMMAND1 to the input of COMMAND2.Note: For simplicity, the OS shell only need to support either input redirection or outputredirection and you do not need to consider them both at the same shell. Similarly, you shell only need to support one pipe although you can implement multiplepipes, which may lead to bonus points (please refer to Section 3.5).Your OS shell support executing multiple commands in one line. For example,$ mkdir ddd; ls text.txt; mv text.txt dddIn this way, a directory named ddd is firstly created following by a redirection lscommand to a file namely text.txt. Finally, this file is moved to the created directoryddd.3.4 Job controlThe OS shell need to support basic job controls of a Unix Shell.Kill a job However, the user must be able to kill the current child processes by sendingit a SIGINT signal, typically by typing Ctrl-c. A SIGINT signal should not kill OS shellitself.Suspend a job The user can type Ctrl+z to temporarily suspend a running frontgroundcommand, the shell shall give the user some hints about the suspended command.Specifically, the OS shell shall show the job number of the suspended command, e.g., JobNumSuspended after users type command jobs.Continue a job Then, the user can use the command continue JobNum to let thesuspended job continue to run, where JobNum is the job number assigned by the OSshell.List all the running jobs The user can type jobs to display all the current runningjobs in your system as well as the status of the jobs. For example,3[OS shell:/home/S171234]$ jobs[1] Suspended[2] Running[3] TerminatedPut a foreground job to background the user can type Ctrl+z to temporarilysuspend a running front-ground command, the shell shall give the user some hints aboutthe suspended command. Specifically, the OS shell shall give the job number of the suspendedcommand, e.g., JobNum Suspended. Then, the user can use the command bgJobNum to put the suspended job to background, where JobNum is the job numberassigned by the OS shell.Put a background job to foreground the user can type command to run a command(job) in background (Note that this command shall run relatively a long time, e.g., sleep1000 ). The OS shell shall also give a hint about the background job information (i.e., thejob number) so that the user can seize the control the job later. Before the background jobend, the user can put it to the foreground by using the command fg JobNum and thenthe background shall run in foreground.status this command should print the status of the last command executed. Commandsreturn 0 as the indication of success, and any non-zero value to indicate the failure.3.5 Bonus Part (at most 10 points)There is an optional part of the shell, which may lead to bonus points in your final score.3.5.1 Better PromptYour shell should support better user-friendly prompt:[OS server:/home/S171234]$ _where OS server is the hostname and /home/S171234 is the current working directorywhen the shell is invoked.3.5.2 Logical operating of multiple commandsYour OS shell may support AND Operator () and OR Operator (kk).For example,$ haha || echo Failed -OS Shell: haha: command not found Failed $ ls echo Success text.txt Success 3.5.3 Multiple pipesThe OS shell can support multiple pipes (more than 2 pipes) and the combination of I/Oredirections with multiple pipes. For example, The OS shell shall support the command likels R / | grep url* | wc l result.txt43.6 ReportsSubmit a report including: A design report including the system architecture, the flowcharts and descriptions ofeach module. A short manual about your program including how to use your program. All the source files (e.g., *.c or *.cpp and *.h) and Makefile (if any). The executable files are not necessary to be submitted.3.7 Requirements You are not allowed to invoke the system(3) library call. Otherwise, you would score 0marks for this assignment. You are not allowed to invoke any existing shell programs in this assignment. Otherwise,you would score 0 marks for this assignment.Note that the phrase existing shell programs implies the shell programs installed in theoperating system including, but not restricted to, /bin/sh /bin/bash, etc.4 Milestones1. Make sure you can understand all the assumptions and regulations of the system inSection 3.2. Phase 1 According to the specifications in Section 3.2, you shall implement the basic shell. Your program must be thoroughly tested. You should make sure that you havetest the cases both for successful and for unsuccessful operations.3. Phase 2 According to the specifications in Section 3.3, you shall implement the redirection,the pipe of the shell and multiple commands. Your program must be thoroughly tested.4. Phase 3 According to the specifications in Section 3.4, you shall implement the job control. Your program must be thoroughly tested.5. Report submission. After all the above phases, you shall submit a project report asspecified in Section 3.6.55 Running environmentCentOS 7.26 Grading Policy Phase 1 (30%): Demonstration Phase 2 (30%): Demonstration Phase 3 (30%): Demonstration Report (10%)Late demonstration of each phase will lead to the score penalty.7 SubmissionPlease submit your reports and program codes through https://moodle.must.edu.mo/.8 PlagiarismProgramming is a creative work and the academic regulations that apply to plagiarizing prosealso apply to plagiarizing code. Rights, Rules, and Responsibilities defines plagiarism as theuse of any outside source without proper acknowledgment. It ranges from verbatim copying(e.g., cutting-and-pasting code) to thorough paraphrasing (e.g., changing variable names orrearranging code). We use sophisticated tools to detect plagiarism and our teaching stafftakes the issue very seriously.We refer alleged academic violations (including plagiarism and abetting plagiarism) to theDiscipline Committee under Academic Office. If found responsible, the typical penalty is thefailure for this course plus whatever penalty that is stated in University Student Handbook.6如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
“
添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导。