Programming Assignment 1 - CLI PDF

Title Programming Assignment 1 - CLI
Author Dina Yashaev
Course Operating Systems
Institution Concordia University
Pages 3
File Size 154.8 KB
File Type PDF
Total Downloads 35
Total Views 133

Summary

Command Line Interpreter to be coded either in java, c++ or python...


Description

Concordi diaa University Electrical aan nd Computer Engineering COEN 346 Lab Assignment #1 Description Command Line Inte rpreter

A Command Line Interpreter (CLI) (also called Command Line Interface) is an interface that can be used to interact with computers using commands issued as lines of text, referred to as command lines. In the context of an operating system (OS), a shell is the CLI one can use to invoke various operating system services (process management, file management, etc.). A shell usually comes with three classes of commands: • •



Internal: commands the shell understands and does not use any other executable to run them (builtin instructions). Included: commands that are provided by executables that are not part of the shell. These executables usually come with the basic installation of the OS. The shell can find these executables in a set of folders (comma separated) pre-configured in an environment variable called PATH. External: commands provided by computer programs that are installed on top of the OS. They do not come with a basic installation of the operating system as they require some software to be installed first. The shell can recognize these commands because the user usually invokes them using the absolute or relative path to their executables.

When the shell is first initiated, it shows the line indicating that it is ready to receive a command. Usually this line is “nameoftheuser@nameofthehost$”. When a user invokes a command, the shell first tries to invoke it as an internal command. If the shell fails to recognize the command, it looks for an executable matching the name of the command in one of the folders pre-configured in the PATH environment variable. If none is found, the shell then processes the command line as a path, isolates the name of the executable (from the last detected “/” character to the end of the command line), and tries to execute an executable with a matching name in the indicated folder (path from the beginning of the command line to the last detected “/” character). If none of these methods manages to execute the command line the shell reports to the user that the entered command is unknown. From the perspective of the input/output, the user has multiple options. For instance, the user can pass parameters to the shell from a file or using the shell’s input stream. Similarly, the user can either choose to display the output in the shell or redirect the output to a file. If a user chooses to redirect the output to a file, they have two options: • •

Delete an existing file with similar name (if any) and write into a new one. Append to an existing file with similar name (if any).

Shells usually provide built-in constructs to enable these various modes of interactions between the user and the shell.

As previously mentioned, shells are used to invoke some OS services. This can only imply that in addition to the process running the shell itself, for every issued command the shell creates a new process to execute it. Note that a shell needs to fork new processes only for included and external commands, while the internal commands can be executed within the same process running the shell. Moreover, there are two modes in which a command can be run: • •

In the foreground: meaning that shell cannot take any other command lines until the current command is finished. In the background: meaning that once the command is invoked, the shell becomes ready to take the next command line and does not wait for the current command to finish.

The goal of this first programming assignment is to develop a mini-shell program. The shell program will have its own set of internal commands, a set of executables that are available in a folder accessible by your program to simulate a folder in the PATH, and a set of external executables to place in your current working directory to play the role of external commands. The process running the shell should be simulated using a thread, and for every invoked (included or external) command you should create one thread. Your shell should be able to redirect output of a command to a file, with support of both modes (appending to existing file or deleting and creating a new one with the same name). The shell should also enable the execution of commands in both the foreground and the background. You will be provided with a sample folder structure that you can use to test your program, and will also be used during the demos that will be scheduled later. The built-in constructs of the shell: • • • • •

Echo param: prints the parameter given as argument to appropriate streams (file, shell screen). Exit: to exit the program. Command -> filename: redirects the output of command to a file named filename. If a file with the same name already exists it deletes it and creates a new one. Command ->> filename: appends the output of command to a file with name filename. If the file does not already exist, it creates it. Command &: executes command in the background. A command is by default executed in the foreground.

Your program will take as input a file that contains the username in the first line, the hostname in the second line, and the content of the PATH in the third line. When the program is started it prompts the user to enter a command by displaying “username@hostname$”. Whenever the user enters a command, the program executes it. If the command is to be executed in the foreground, the shell should wait for the command to be finished before prompting the user to enter the next command. If the command is to be executed in the background the shell just launches it and prompts the user for the next command. The shell keeps prompting the user to enter the next command until the user enters “exit” and that is when your shell should finish its execution. Keep in mind that you should have a thread (other than the main thread) for the shell, and a thread for each included or external command invocation (regardless if it is in the background or foreground).

Sample input file: coen346User hots1 PATH=usr/bin,bin,usr/local/bin,usr/someprog/bin Sample execution: coen346User@host1$ echo “Hello coen46” Hello coen346 coen346User@host1$ echo “Hello coen346” -> output.txt coen346User@host1$ datetime January 1, 1970, 00:00:00 coen346User@host1$ ./myownExecutable.exe ->> output.txt & coen346User@host1$ anotherExecutable unknown command: anotherExecutable coen346User@host1$ exit This programming assignment should be done in a group of three students. Please note that you cannot change your group after submitting the first assignment. The deliverable consists of the following items: 1. A well-commented code. 2. A two-page report specifying the high-level description of the code (description of the methods/functions/threads and the flow of the program). The report should also include a brief conclusion, discussing you experience with threading and your suggestion for an example application of threads other than the ones discussed so far. Do not forget to write the names of all team members in the report. This assignment will count for 25% of your total mark for programming assignments. Also, for this assignment 80% of the mark is for the quality and correctness of your code, and 20% for the quality of your report. The code and the report should be submitted in one zip file through Moodle by Friday February 11th, 2022 (11:59 pm). After submission you will have to demonstrate your work as a team to your TA during a lab session....


Similar Free PDFs