This assignment is intended to introduce you to the process manipulation facilities in the Unix Operating System. You are to implement the program described below on any CCC Unix machines in Java.
You are to write a program that simulates a simple Unix command line shell. Your program will allow a user to enter commands one at a time until s/he types "exit".
Not all commands will be executed externally. Your shell will also have several "built-in" commands. These commands will be handled internally by your java-shell and will not be executed. The built-in commands are:
exit
-- causes your java-shell to exit.
cd
dir -- causes your java-shell to change
the working directory to dir.
Note, however, that your program should have error checking. You must check the return values from system calls and print appropriate error messages to the user, when required.
I've put up some Java code samples on the course web page.
Here are only some of the many online sites at Sun you may find useful for programming in Java:
There are lots of other places to go for Java information. Here are a few:
exec()
-- to create and run a new process.
waitFor()
-- to wait for a process to terminate.
StringTokenizer
-- to parse input.
String
-- for string manipulation.
A few recommendations if you find yourself struggling (in order):
exec()
with a hard-coded command (ie - ls -l
).
exit
command.
waitFor()
call.
cd
command.
Remember, do each step thoroughly. Make sure the step you are on works well and you understand it before going to the next step.
You should observe how your tiny shell works compared to a
full-fledged Unix shell, such as tcsh
or
bash
. What are some of the process features the Unix
shell has that your tiny shell does not?
Shells typically allow processes to be run in "background" mode using the '&' character. In background mode, the shell does not wait for the current process to complete but instead prompts the user for the next command. Briefly describe changes you would make to your code to support the '&' character.
Will your jsh
be portable to every program
that has a java virtual machine? Why or why not?
cd
command. Subtract one letter grade.
Note, one letter grade is worth approximately 10% of the Project points.
You should roughly follow the CS department's documentation standard. The main information I'd like you to have from the documentation standard is; author, date, project id, language, OS dependencies, description and building information. In addition, there are a couple of short-answer questions for the lab that you should include (see above). Do note, however, that this information does not take the place of normal comments in your code!
All this information can appear as code comments in the header of your program or in a separate file. If you choose to put the information in a separate file, please name the file something like README. Also, be sure to turn-in you file when you turn-in your source code!
Here is a sample of the information you should have:
Author: Mark Claypool Date: 9/9/99 Project ID: Project 1 CS Class: CS3013 Programming Language: Java OS/Hardware dependencies: Digital Unix Problem Description: This program implements a small shell that does blah, blah, blah How to build the program: java jsh.java Answers:You will turn in your assignment using the "turn-in" program. Check here for information on how to turn in your assignments.
Send all questions to the TA mailing list.