Assignment 1—UNIX Shell



Assignment 1—UNIX Shell

Due 10pm Thursday, January 29

Overview

The objective of this assignment is to help you gain familiarity with process creation in UNIX. You are to program a simple UNIX shell, an interactive program that allows users to launch other programs. Examples of common shells include bash, tsh, and csh. If you are unfamiliar with UNIX shell concepts (prompts, command line arguments, foreground, background), use Google to do the necessary background research.

Requirements

• This assignment must be completed on the ITC Sun computers using C or C++.

• Your shell must present the user with a prompt. You are free to select any reasonable prompt you like.

• Your shell must allow the user to enter a command line, including program options. You may assume that command lines are well-formed. We want to acquaint you with the functioning of a shell, and don’t want you to waste time on sophisticated parsing. We’re not going to test it with any esoteric commands.

• Your shell must allow the user to specify whether the command should be run in the background or foreground. The user will indicate that a command should be run in the background by including an ampersand (&) as the last command line argument. If no ampersand is included, assume the process should be run in the foreground. Modest partial credit will be given for a shell that compiles and operates successfully, even if it can only run commands in the foreground.

• If the user requested that the command be run in the background, then your shell should immediately present a prompt after starting the new process. You can decide how to handle the new program’s output text.

• If the user requests a foreground process, the shell should wait until the new process terminates before presenting a new prompt. All output generated by the new process should be displayed in the console.

Analysis Section

1. Use your shell to execute a long-running background task that produces no output, for example ls –alR / > /dev/null. While this background task is running, use your shell to run the ps UNIX command to list all of the processes in the job queue that are owned by you. Make sure to set ps’s command line options so that it shows detailed information about the processes that you own. In this list, you should see your shell and the ps process. Turn in a transcript of this investigation.

2. Use your shell to start an additional, nested copy of your shell in foreground mode. Is there any danger that these two processes will interfere with one another?

3. Consider the following source code:

for (i = 0; i < N; i++) {

fork();

printf(“hello world”);

}

Roughly estimate how large N could be before your UNIX system would run out of memory. Make whatever assumptions that you feel are necessary, just be sure to clearly state them in your answers.

Turn In

Email a document with your answers to the analysis section, and a pointer to your source code, to the cs414@cs account by 10pm on Thursday, January 29. Please don’t email the actual source files, and please be sure the source files in your account are world readable. In the source-code directory, provide a README identifying all essential files and any important issues needed for successful compilation. Makefiles are preferred.

Your document can be in any reasonable format, eg ascii, PDF, Word. Please be sure to include the pledge and both partners’ names. Your document should also state any assumptions or specific implementation decisions that you think are relevant.

Remember, you are free to discuss solution approaches with your classmates, whether in person or on the discussion board. You are not free to copy code or text.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download

To fulfill the demand for quickly locating and searching documents.

It is intelligent file search solution for home and business.

Literature Lottery

Related searches