Introduction
linux,c/c++,shell,date,env,curr,
cd,DIR,shell,,exec(),fork()
Requirement
CSE 410 Fall2017
Computer Project #4
Assignment Overview
For this assignment, you are to design and implement a C/C++ program that will serve as abasic command-line
interpreter (shell). You will extend your work from the previous project.
It is worth 40 points (4% of course grade) and must be completed no later than 11:59 PM on Thursday, 10/12.
Assignment Deliverables
The deliverables for this assignment are the following files:
proj04.makefile – the makefile which produces “proj04”
proj04.student.c – the source code file for your solution
Be sure to use the specified file names and to submit your files for grading via theCSE Handin system before the
project deadline.
Assignment Specifications
1. The program will repeatedly display a prompt containing the sequence number of the current command
(starting at 1) and the username of the user executing the program. This information will be enclosed in the
characters ‘’. For example:
The sequence number and username will be separated by a singlespace.
2. After displaying the prompt, the program will repeatedly read one line of input from the user and process it. An
input line is defined as a sequence of zero or more tokens (character strings), separated by one or more delimiters
(blanks and tabs), ending with a newline character. The ampersand character (‘’) is defined to be a separate
token. There will be no more than 128 characters in a line.
If the first token is the name of a built-in command (listed below), then the program will take the appropriate
action. Otherwise, the program will assume that it is an external command (the name of a file containing an
executable program).
3. The program will recognize the following built-in commands:
quit terminate the shell process
date display current date and time
env manage environment variables
curr display absolute pathname of current working directory
cd manage current working directory
Built-in commands will be completely processed by the program (the program will not create a child process to
perform. the processing).
4. The command “date” will display the current date and time in a human-readable format.
5. The command “env” will display the user’s environment variables in a format similar to “setenv” in the C shell.
6. The command “curr” will display the absolute pathname of the current working directory.
7. The command “cd” will manage the current working directory.
a) The command “cd” without any other tokens will reset the current working directory to be the user’s home
directory.
b) The command “cd DIR” will reset the current working directory to be “DIR”, where that token may be a
relative or absolute pathname.
c) The command “cd ~USER” will reset the current working directory to be the home directory of the user
with username USER. As a special case, the symbol “~” represents the home directory of the current user.
8. For external commands, the program will create a child process; the child process will use a member of the
“exec” family of functions to execute the external command.
If the last token is an ampersand (‘’) and the command is an external command, the program will execute the
command in the background. That is, the program will not wait until the completion of the given external
command before continuing with its processing.
9. The program will perform. appropriate error handling. It will display an appropriate message if the user’s
command fails in any way.
Assignment Notes
1. As stated above, your source code file will be named “proj04.student.c”; that source code file may contain C or
C++ statements.
2. You must use “g++” to translate your source code file in the CSE Linux environment.
3. You must be careful to distinguish between the parent process and the child process when using function
“fork”. Otherwise, you might mistakenly create a process which clones itself indefinitely; that process would then
fill up all of the entries in the process table and prevent anyone else from using the system.
To minimize the impact on other users, the following policies will be used:
a) Use the appropriate shell command to limit the number of processes that you can create. For example, to limit
the number of your processes to a maximum of 50:
limit maxproc50 (under “tcsh”)
ulimit–u50 (under “bash”)
b) You must execute your program on the server “cse410.cse.msu.edu”. You may NOT execute your program on
any other CSE server (such as “arctic”, “black”, “xserver” or “xserver2”). If you execute your program on any server
except “cse410” and you cause a system problem, you will receive a score of 0 on this assignment and sanctions
from the Department with respect to your computer account.
c) If you’re using the server “cse410” and you mistakenly create a set of runaway processes, send email to
“” and “” so that the server can be rebooted.