$39
In this project, the students will learn and become familiar with the concepts of system-level process control, process signaling, interprocess communication, and running processes and jobs in the background in Linux Shell. Students will learn this by programming a simple yet customized Linux shell that supports all the aforementioned functionalities in their own programmed shell.
Linux Shell. A shell is an interactive command-line terminal program whose primary purpose is to execute user-provided commands and run other programs. A shell repeatedly prints a prompt, waits for a command line on the terminal via stdin, and then performs action as directed by the contents of the command line.
Project Prerequisites. Familiarity with C/C++ programming and Linux shell commands.
This project consists of three incremental phases, where each phase must be done for the next phase, i.e., You will be extending the functionality of your shell in every project phase.
2 Project Phase I: Building and Testing Your Shell (Points: 30)
In this phase, Your first task is to write a simple shell and starting processes is the main function of linux shells.
So, writing a shell means that you need to know exactly what is going on with processes and how they start.
Your shell should be able to execute the basic internal shell commands such as,
As illustrated in Figure 1, commands should be executed by the child process created via forking by the parent process except exit and cd.
Figure 1: Main Structure of Shell Program
CSE4100: System Programming Project #2: MyShell
Here is an example of how your shell works.
Makefile README myshell myshell.c CSE4100-SP-P2> mkdir myshell-dir CSE4100-SP-P2> touch myshell-dir/cse4100 CSE4100-SP-P2> ls
Makefile README myshell myshell.c myshell-dir CSE4100-SP-P2> cd myshell-dir && ls
cse4100 CSE4100-SP-P2> cd .. CSE4100-SP-P2> ls
Makefile README myshell myshell.c myshell-dir
CSE4100-SP-P2> exit
Hints: The shell mainly relies on fork( ) and exec( ) system calls. These two system calls are actually the building blocks for how most programs are executed on Linux. First, an existing process forks itself into two separate ones. Then, the child uses exec( ) to replace itself with a new program.
Your shell is constantly running loop with three functionalities inside;
do{
} while (true);
Note: Please refer to the man pages for the fork(), exec(), wait(), and other related system calls.
Evaluation: Your shell should perform all the functionalities explained in task specifications above.
3 Project Phase II: Redirection and Pipe (Points: 30)
In this phase, you will be extending the functionality of the simple shell example that you programmed in project phase I. Start by creating a new process for each command in the pipeline and making the parent wait for the last command. This will allow running simple commands such as “ls -al | grep filename”. The key idea is; passing the output of one process as input to another. Note that you can have multiple chains of pipes as your command line argument.
Figure 2: Main Structure of Shell Program with pipe and redirection
CSE4100: System Programming Project #2: MyShell
Hints: The Pipe is a command in Linux that lets you use two or more commands such that the output of one command serves as input to the next. In short, the output of each process acts as input to the next one, like a pipeline. The simplest way to solve multiple pipes in your command line arguments; is to use a recursive function called until there are no more piped commands during parsing.
Note: Please consult the man pages for the dup(), dup2() system calls.
Note: In this phase, You don’t need to implement redirection. However, redirection works in a similar way to pipe. The difference is that redirection handles file-related commands.
Following shell commands with piping can be evaluated, e.g.,
4 Project Phase III: Run Processes in Background (Points: 40)
It is the last phase of your MyShell project, where you enable your shell to run processes in the background. Linux shells support the notion of job control, which allows users to move jobs back and forth between background and foreground, and to change the process state (running, stopped, or terminated) of the processes in a job.
Your shell must start a command in the background if an ‘&’ is given in the command line arguments. Besides, your shell must also provide various built-in commands that support job control.
Following shell commands with piping can be evaluated, e.g.,
Note that one should not be required to separate the ‘’ from the command by a space. For example, the commands ‘sort foo.txt &’, and ‘sort foo.txt&’ and ‘sort foo.txt &’ (blanks after the ampersand) are all valid.
Figure 3: Main Structure of Shell Program with all features
Hints: When pressing ctrl-c causes a SIGINT signal to be delivered to each process in the foreground job. The default action for SIGINT is to terminate the process. Similarly, pressing ctrl-z causes a SIGTSTP signal to be delivered to each process in the foreground job. The default action for SIGTSTP is to place a process in the stopped state, where it remains until it is awakened by receiving a SIGCONT signal.
Note: Please consult the registering signal handlers in Chapter 8 to complete this project phase.
SIGINT, SIGSTP, and SIGCONT are must-read items.
Following shell commands can be evaluated for this phase, e.g.,
CSE4100: System Programming Project #2: MyShell
Hand-In Specifications: The submission should contain only source code file(s), including file(s), a Makefile, and the readme file. No executable program should be included. TA, in charge of grading your project, will automatically rebuild your shell program from the provided source code.
Please strictly follow the submission instruction below. If you not, you may get a penalty on your overall project score.
Attachment File:
• Documnet(about phase 1, 2, 3) (20 point)
Following is an example of a submission.
$~> ls
prj2_20221234.tar
$~> tar -xvf prj2_20221234.tar
$~> ls
20221234 prj2_20221234.tar
$~> tree
20221234
document.docx
phase1
Makefile
README.md
myshell.c
myshell.h
phase2
Makefile
README.md
myshell.c
myshell.h
phase3
Makefile
README.md
myshell.c
myshell.h
All students are requested to upload the archived source files on eclass (cyber campus).
Note:Please make sure to compile your source code on CSPRO server, as the TA will build and compile your submitted project on that server. If the submitted code does not compile it cannot be scored!!!
CSE4100: System Programming Project #2: MyShell
6.1 Best practices the system programmers must comply to
WHAT YOU MUST DO:
WHAT YOU MUST NOT DO: