CS625
01
Assignment 1
Due 09/28/2017
Do either part I or Part II
Part I: MINIX OS Architecture
Read Appendices B MINIX 3 Source Code Listing.
Reverse engineer the source code to identify the relations among the files. Draw
a detailed block diagram of the MINIX with all relationships listed. Write a
report to further descript the MINIX OS program structure and the process
model, process states implemented.
Assignment
Hand-in Policies:
1) Email me a Microsoft word report that describes the block
diagram and MINIX OS program structure.
2) Demonstrate your work in a power-point presentation in the
class on the due day.
Part II: OS Shell Project on cs99
Write a C/C++
program to simulate a simple shell (command interpreter) on CS99 UNIX/LINUX.
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 MSH (short for My SHell) and its initial prompt should
be ">".
1. MSH should
first prompt user for the login name and password. The list of login names and
passwords should be stored in an external file.
MSH will continue with a new
"MSH> " prompt if the login is successfully.
- The password stored in the table or external
file must be encrypted. You should use the crypt(…)
function to encrypt the password.
2. MSH 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 */
MSH will analyze the command. If the command
is one of the following commands supported by the MSH, it forks a new process to execute the command. Otherwise it
prints the error message to indicate an invalid command.
The MSH commands
should be initially stored in an external file and read into a command array
(or a hash table) when MSH starts.
The 8 commands supported by the MSH are:
mypwd
/* Change the password – Write your own MSH function to change the password */
mycopy
fileName1 fileName2 [fileName3]
/* Copies the contents of fileName1
to fileName2
or copy fileName1 and fileName2
to fileName3 if fileName3 is provided. You may use the UNIX command “cat” or “cp” to copy the files*/
myedit [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 “pico” to
edit the file */
myps [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 */
mydf [filesystem] /*
display numbers of free disk blocks in kbyte, or
display numbers of free disk blocks in kbyte in one
filesystem
if the filesystem is
provided. You may use the UNIX command “df –k | grep filesystem” to
display free memory status in one filesystem */
mysearch 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 */
myhistory /*
list of all previous commands executed - Write your own MSH function to list
the history */
mylogout /*
the MSH should exit the shell after other commands are completed. */
(Extra credit: Program the upper arrow key to list the
previous command executed.)
3) MSH 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 "MSH>"
prompt if the command is in a foreground process, otherwise it simply go back
to the "MSH>" prompt if the command is in a background process.
- The command should be executed as a
background process if a “&” sign
is followed at the end of the command.
4) The main()
function of your program should follow the following program structure.
…
build_command(); /*
read in the commands into a table or hash 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); /* status must be a hex number */
/* For example:
LOGOUTCODE is 0x0500 is child terminated with the command exit(5)
*/
} /* end of parent code */
} else { /*
Child code */
exec_command
(command, parameters); /* execute
command */
exit(0);
} /* end of child code */
} else { cout << “Invalid command, try again\n”; }
i++;
}
Testing
Requirements:
Test every command supported by the MSH
in a foreground process. Test just one command in a background process.
Assignment
Hand-in Policies:
1) Submit a Microsoft word report in the dropbox
on the Sakai class web site that describes your program structure and
operations (Good program modular design, data structures, algorithms, and
internal documentation are part of the grade).
Attach the programs source code and run
results (screen shots) on your report.
2) Demonstrate your shell program operation in the class on the
due day.