CS519
01
Assignment 1
Due 06/11/2008
Part I: Report of Lecture Notes and Textbook studied on OS Concepts (Ch
1), Processes & Threads (Ch 2), and Deadlocks (Ch6)
Write a Microsoft report to summarize your self-study activities. The report must have the following.
1. The time and date of your study and the topics covered in each study session.
2.
The summary of each topic studied.
3. Questions and answers in each study session
(you may make up the questions or use the problems at the end of each chapter
from the textbook.)
4. Conclusions of knowledge learned.
Email the report to the instructor
on the due day.
Part II: OS Shell Project on cs1
Write a C/C++ program to simulate a simple
shell (command interpreter) on CS1 UNIX (Solaris).
The program operations will be used to illustrate the process creation,
synchronization, and execution using FORK, WAIT, and SYSTEM Unix commands The
shell should be called SSH (short for Simple SHell)
and its initial prompt should be "> ".
1. SSH should first prompt user for the login
name and password. The list of login names and passwords should be stored in a
table.
SSH will continue with a new "ssh> " prompt if the login
is successfully.
- The
password stored in the table must be encrypted.
- You may use any available encryption
function or design your own encryption function to encrypt the password.
2. SSH should then read the command and
parameters entered by the user,
where the syntax of commands is:
command [parameter | [parameter]*] /* [] means optional, | means or, * means 0 or more */
SSH will
analyze the command. If the command is one of the following commands
supported by the SSH, it forks a new process to execute
the command.
Otherwise it prints the error message.
The SSH commands should be initially stored in an external file and read into a command array when SSH starts.
The initial set of 7 commands supported by the SSH are:
newpwd /* Change the password
Write your own SSH function to change the password */
copy fileName1 fileName2 [fileName3]
/* Copies the contents of fileName1
and fileName2 onto the screen
or copy fileName1 and fileName2
to fileName3 if fileName3 is provided. You may use the UNIX command cat or
cp to copy the files*/
edit [subdirName].fileName
/* edit an existed file in the
current directory or in a subdirectory if the subdirName
is provided. You may use the UNIX command vi or pico
to edit the file */
display [loginName]
/* display the status of all current processes, or display the processes belong
to the user
if the loginName
is provided. You may use the UNIX
command ps ef | grep loginName to display processes status */
search word fileName
/* search a word in a file.
Print the lines where the word
is found. You may use the UNIX command grep to
search a word in the file */
history /* list of all previous commands
executed - Write your own SSH function to list the history */
logout /* the SSH should exit the shell
after other commands are completed. */
(Extra credit: Program the upper arrow key to list the previous command executed.)
(You may learn UNIX commands either on the internet or use man UNIX command on cs1 to list the manual page, for example use man ls to list the manual page of ls command.)
3) SSH should fork a child process to execute
the command. The parent process will wait for the
termination of the child process before
go back to the "ssh>"
prompt if the command is in a foreground process, otherwise it simply go back
to the "ssh>" prompt if the command is
in a background process.
- The command should be executed as a
background process if a & sign
is followed with the command.
4) The main() function should follow the following program structure.
build_command(); /* read in the commands into a table */
user_login(); /* Authenticate the user */
while (i < N) { /* repeat maximum N times */
type_prompt( ); /* display prompt */
n=read_command (command, parameters, background) /* input from terminal */
if (n>0) { /* valid command */
if (pid = fork() != 0) { /* Parent code */
if !(background) {
pid = wait( &status); /* wait for child to exit */
if (status == LOGOUTCODE) exit(0);
}
} else { /* Child code */
exec_command (command, parameters); /* execute command */
exit(0);
}
} else { cout << Invalide command, try again\n; }
}
Testing Requirements:
Test every command supported by the SSH
in a foreground process. Test one command in a background process.
Assignment Hand-in Policies:
1) Email me a Microsoft word report that describe your program
structure and operations.
Attach the programs source code and run
results (screen shots) on your report.
2) Good program modular design, data structures, algorithms, and
internal documentation are part of the grade.