Docsity

Programming Assignment 2 - Operating Systems | COP 4610, Assignments of Operating Systems

Toggle sidebar
bg1
COP4610 - Introduction to Operating System Principles
Programming Assignment 2 : Interactive Shell Program
Assigned Monday 22, 2008
Due Sunday Oct 12, 2008
Goal
In this project you will write an interactive shell program. Your shell will implement a few basic
commands, as well as learn how to create child processes. Furthermore, you will learn how to perform
inter-process communication using the standard UNIX pipe and redirection mechanisms.
Project Description
In this assignment, you will develop a shell program called “coolshell”. This shell program will be a
stripped down version of a common Linux shell. Your shell should be able to execute any binary/
program or command requested by the user.
Project Specification
As an example, the following illustrates the order of execution of “coolshell”:
%> ./coolshell
coolshell:~> ls
[ output goes here ]
coolshell:~> exit
exiting coolshell ...
%>
(Note: When process is running in foreground, process should complete
execution before returning to the prompt)
Your “coolshell” program must support the following built in commands:
cd Change the present working directory
exit Exit from your interactive shell program
echo Print the input. If prefix with $, print the current environment variable
ls List the files and folders in the current directory.
hist Displays the last 15 folders accessed, sorted oldest first.
08/29/05 1/3
pf3

Partial preview of the text

Download Programming Assignment 2 - Operating Systems | COP 4610 and more Assignments Operating Systems in PDF only on Docsity!

Programming Assignment 2 : Interactive Shell Program Assigned Monday 22, 2008 Due Sunday Oct 12, 2008 Goal In this project you will write an interactive shell program. Your shell will implement a few basic commands, as well as learn how to create child processes. Furthermore, you will learn how to perform inter-process communication using the standard UNIX pipe and redirection mechanisms. Project Description In this assignment, you will develop a shell program called “coolshell”. This shell program will be a stripped down version of a common Linux shell. Your shell should be able to execute any binary/ program or command requested by the user. Project Specification As an example, the following illustrates the order of execution of “coolshell” : %> ./coolshell coolshell:~> ls [ output goes here ] coolshell:~> exit exiting coolshell ... %> (Note: When process is running in foreground, process should complete execution before returning to the prompt) Your “coolshell” program must support the following built in commands: cd Change the present working directory exit Exit from your interactive shell program echo Print the input. If prefix with $, print the current environment variable ls List the files and folders in the current directory. hist Displays the last 15 folders accessed, sorted oldest first.

Your shell’s prompt must follow these rules:

  1. Displays “coolshell” followed by a colon.
  2. Next displays the present working directory. a. If the value in the $HOME variable is found in the present working directory, replace it with a ~. b. If the value you are going to print is longer than 3 folders deep, only show the last 3 folders. The ~ should not be shown in this case. c. A leading slash should only be shown if it is a root level folder.
  3. Lastly display a > Examples: When in your home directory: (i.e /home/majors/yourname) coolshell:~> When 1 subdirectory deep within your home directory (i.e /home/majors/yourname/project2) coolshell:~/project2> When in the proc folder coolshell:/proc> When in /proc/ide/ide0/had coolshell:ide/ide0/had> In addition, your “coolshell” program must be able to do the following in order to get full credit:
  4. Use the fork(..) and execv(..) system call to replace the process image of the newly created child processes. Using the system system call is strictly prohibited.
  5. Support running more than one background process using the ‘&’ directive. Background process example: coolshell:~> ./myprogram.x & coolshell:~> (Note: The ./myprogram.x binary will run in the background until it terminates. With the ‘&’ directive, the user will return to the prompt immediately. Meantime, ./myprogram.x that is running is the background may or may not generate output onto screen. Please make sure you test for both cases.)
  6. Perform redirection using the ‘>’ and ‘<’ directive. Here, you are only required to perform a single level redirection. In other words, if ‘<’ is used, then ‘>’ will not be used and vice versa. Output Redirection Example: