This problem set is divided into two parts (see Deadlines below). Here is the specification of the entire problem set; features marked with asterisks are to be implemented in the second part of the assignment.
You may assume that each simple command is of the form
'command arguments redirection'
and that the syntax
'command redirection arguments'
is illegal.
In part 2 of this assignment, you will also handle '&' on the command line (see Background processes and job control).
When a file is found that has proper execute permissions, the shell forks a new process and passes it, along with its arguments, to the OS using the execv or execl system call. (Do not use the execvp or execlp calls.) The OS then attempts to overlay the new process with the desired program. If the file is an executable binary the OS succeeds, and begins executing the new process. If the file does not have execute permissions, or if the pathname matches a directory, a "permission denied" message is displayed. If the pathname cannot be resolved a "command not found" message is displayed. If either of these errors occur with any component of a pipeline the entire pipeline is aborted, although some of the components of the pipeline may have already started running.
A pipeline is completed (i.e., returns to the prompt) only when all the commands that form a part of the pipeline and that are being executed in the foreground are completed.
Environment variables may be accessed via the setenv and unsetenv built-in commands. Initially no environment variables are set, i.e. ish does not inherit environment variables from its parent. ish maintains environment variables internally, and may not use the C library routines putenv or getenv. When a program is exec'ed the environment variables are passed as parameters to execve. The only two environment variables that ish needs to interpret are PATH and HOME; all other environment variables can be set and unset in ish using the above built-in commands, but are not interpreted.
[1] 1234
Note that the special character & at the command line causes asynchronous execution of the preceding pipeline. The shell does not wait for the pipeline to finish; instead, it displays the job number and associated process IDs. The shell associates a numbered job with each command sequence, to keep track of those commands that are running in the background or have been stopped with TSTP signals (typically CTRL-Z). Jobs are put into the foreground using the tcsetpgrp system call.
To see the current list of jobs, use the jobs built-in command. The job most recently stopped (or put into the background if none are stopped) is referred to as the current job.
To manipulate jobs, refer to the built-in commands bg, fg, and kill. A reference to a job begins with a '%'. Refer to job number j as in: 'kill %j'. A job running in the background stops when it attempts to read from the terminal.
* bg %job ... | Run the specified job in the background. |
cd [ dir ] | Change the shell's working directory to directory dir.If no argument is given, change to the home directory of the user (which is given by value of HOME). |
exit | Exit ish. |
* fg %job | Bring the specified job into the foreground. |
* jobs | List the active jobs under job control. |
* kill %job ... | Send the TERM (terminate) signal to the job indicated. To insure termination, the job is also sent a CONT (continue) signal. |
printenv | Print the environment variables. |
setenv [ VAR [ word ] ]
|
With no arguments, setenv displays all environment variables. With the VAR argument, it sets the environment variable VAR to have an empty (null) value. (By convention, environment variables are normally given upper-case names.) With both VAR and word arguments, setenv sets the named environment variable to the value word, which must be either a single word or a quoted string. |
unsetenv VAR | Remove VAR from the environment. |
/u/cs217/bin/submit 7
/u/cs217/bin/submit 9
If you miss points on Part 1 you will have the opportunity to resubmit by the final due date and receive 70% credit for the problems fixed (i.e., you will have an opportunity to make up 70% of the points missed on Part 1). Late penalty points cannot be made up, but we'll take the larger grade of the one determined as above and 70% of your second submission.