Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Project (System Programming and Linux Shell) I. Project Description The object of this assignment is to gain reasonable experience with some advanced system and

Programming Project (System Programming and Linux Shell)

I. Project Description

The object of this assignment is to gain reasonable experience with some advanced system and OS programming techniques like process creation and management, file descriptors, Input/Output redirection, interprocess communications, pipes, etc. To do so, you will be writing your own command shell (similar to the terminal you typically use in Ubuntu).

As a starting point, use the exercises explained in our class meetings on how to create processes and how to make them execute different programs or commands. The work on the programs in this assignment (Part1, A, B, and C)

II. Requirements Although I am not expecting that you will be implementing a shell with the full services as the commercial edition (due time and resources constraints and course scope), I would love for you to implement as many features as your time allows. Below are some of the features I expect you to implement in your shell:

Things to consider before you start:

The Shell exits if the user enters the command exit. You may assume that each item in the command string is separated on either side by at least one space (e.g., myProgram > outfile rather than myProgram>outfile).

III. Expected Features: Printing the current directory (pwd) Tip: Try getcwd() function in C/C++.

You should allow the user to run and specify commands (and arguments) either by relative or absolute pathnames. Example ( ls -l ). Tip: Try execvp. It will search the path automatically for you. The first argument should be a pointer to command string and the second argument should be a pointer to a C-String array that contains the command string as arg[0] and the other arguments as arg[1] through arg[n].

Tip:

I explained this in class, and you wrote a program for it. See my slides and your records. to learn more about execvp, use the man command on Ubuntu. History of Commands ( history ): You should maintain a history of commands previously used by the user.

You should create a queue (or list) that works in a FIFO fashion, and you should start numbering them with integer numbers starting by 1. The number should be incremented as new lines are entered by the user (including the invalid commands, if any).

TIP: There is a history command in Linux. Try to do something similar by storing the non-empty commands to your dynamic list and print it as needed.

You should allow the shell to redirect STDIN and STDOUT for the new processes by using < and >. For example, ./myExe < infile > outfile would create a new process to run myExe and assign STDIN for the new process to infile and STDOUT for the new process to outfile. In many real shells, it gets much more complicated than this (e.g.,>> to append, > to overwrite, >& redirect STDERR and STDOUT, etc.)! In this assignment, keep it simple. Only < and >

Tip: Use the following c function: dup and dup2.

First open the file (use open or create, open read-only for infiles and create writable for outfiles) and then use dup2. 0 is the file descriptor for STDIN and 1 is the file descriptor for STDOUT.

Besides the examples I posted with my slides, I am willing to post and share more examples with you if needed. Though, literature and the man command are helpful.

5) The shell should be able to handle simple piping operations.

If the user enters the following command:

./myProg1 | ./myProg2

The shell should run the first program and then the second program. However, the second program should not start until the first one is done.

Tip: create more than one process to handle this situation. Use wait () to make the second waits for the first. Use pipe() to establish a communication between them so the first process passes the information to the second via a pipe, if needed.

IV. What will be graded and what are you expected to submit Part 1 (4 programs, warming up) : *********************

A: Write a C/C++ program that forks off (creates) a new child process that sends 3 messages to its parent via a pipe created by the parent process (your main program). Use write and read functions as explained in the class examples.

The 3 messages should be 3 lines with different pieces of information:

Your full name

Your Department

And your email address

Hints: You need to use the following system calls (see the slides posted on Piazza on the topic):

pipe(), fork(), and wait()

B: Rewrite the program from A to be sending 3 messages from the parent to the child.

C: In this question do refactoring on program A so that write and read functions are not used.

Tip/Hint: use dup/dup2, with other output and input statements (e.g., cout, cin)

D (firs part of the shell): In this phase (part 1) you need to work on your terminal (shell simulator) and accomplish the points (1, 2, and 3) explained above.

Part 2: Due Date/Time: *********************** In this phase (part 2) you need to accomplish the points (4 and 5). That is, get your terminal program ready with all the features 1-5.

Note: Extra work will be awarded extra points if you are planning to add more features to your terminal.

Important notes:

Please submit your work to the designated dropbox via Piazza. No submission via emails. I will make myself accessible so never hesitate to contact me if you have any questions. If you use anything from the literature, please cite it and add it as a reference to your work (as comments or on a separate paper submitted with the work.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions