- 作业标题:CSCI 3120 - Assignment 2: A Simple Shell for Linux
- 课程名称:Dalhouse University CSCI 3120 Operating Systems
- 完成周期:3天
1. Assignment Overview
In this assignment, you need to design and implement a C program that serves as a shell (i.e.
command-based interface) for Linux. The shell accepts user commands and executes each
command using a separate process. In addition, the shell provides a history feature that
allows users to access the recently-entered commands.
2. Important Note
There is a zero-tolerance policy on academic offenses such as plagiarism or inappropriate
collaboration. By submitting your solution for this assignment, you acknowledge that the
code submitted is your own work. You also agree that your code may be submitted to a
plagiarism detection software (such as MOSS) that may have servers located outside Canada
unless you have notified me otherwise, in writing, before the submission deadline. Any
suspected act of plagiarism will be reported to the Faculty’s Academic Integrity Officer in
accordance with Dalhousie University’s regulations regarding Academic Integrity. Please
note that:
The assignments are individual assignments. You can discuss the problems with your
friends/classmates, but you need to write your program by yourself. There should not be
much similarity in terms of coding.When you refer to some online resources to complete your program, you need to
understand the mechanism, then write your own code. Your code should not be similar to
the online resources. In addition, you should cite the sources via comments in your program.
3. Detailed Requirements
- Overview: In this assignment, you need to design and implement a C program that serves
as a shell for Linux. The shell accepts user commands and executes each command using a
separate process. In detail, the shell gives the user a prompt, after which the next command
is entered. The example below shows the prompt CSCI3120> and the user’s next command:
cat prog.c (note that this command displays the content of the file prog.c on the
terminal using the UNIX command cat).
CSCI3120> cat prog.c
One technique for implementing a shell is to have the parent process first read what the user
enters on the command line (in this case, cat prog.c), and thereafter create a separate
child process that executes the command. Unless otherwise specified, the parent process
waits for the child to exit before continuing. The separate child process is created using the
fork() system call, and the user’s command is executed using one of the system calls in the
exec() family.
A C program that provides the general operations of a shell is shown in the code snippet
below. The main() function displays the prompt CSCI3120> and outlines the steps to be
carried out after the input from the user has been read. The main() function continually
loops as long as should_run equals 1; when the user enters exit at the prompt, your
program will set should_run to 0 and terminate.
。。。