CMSC 421: Principles of Operating Systems — Spring 2012 — UMBC—Homework 1

Homework 1

Due by 11:59 PM on March 4, 2012

100 points


Problem 1. (50 points) [Keycode: HW1P1]

You will develop a C program that acts as a simple Unix shell. We will call your program the mshell. The mshell accepts user commands form the standard input and then executes each command in its own process. The mshell presents the user a prompt, after which the user enters the next command. A command consists of the name of an executable file together with any input arguments. A command is a string that terminates with '\n'. Upon reading a command to execute, mshell creates a new child process to execute that command, and it waits for it to complete its execution. Upon completion of each command and before printing the prompt for the next command, mshell prints the total number of commands it has executed so far together with the total CPU time (in seconds) and maximum amount of memory used (in Kbytes) to execute all those commands. The mshell terminates on EOF.

Your program should be running in a Linux system.

Problem 2. (50 points) [Keycode: HW1P2]

Consider the producer-consumer problem with a bounded buffer. Suppose that the buffer can hold N items, with each item being a signed integer. Develop a collection of programs (defined below) for the the producer-consumer with the following characteristics. Develop the following C programs: (1) mkBuffer that creates a FIFO buffer of capacity N integers. T (2) rmBuffer that destroys the buffer. (3) putBuffer that appends a integer given on the command-line to the buffer. Your program should wait if the buffer is full. (4) getBuffer that removes the first item (eg the top of the FIFO buffer) from the buffer and print it on the standard output. Your program should wait if the buffer is empty. (5) printBuffer: that prints the number of items in the buffer and the contents of the buffer in FIFO order on the stdout.

You programs should run correctly in a Linux system. Moreover your programs should be using the named shared memory, memory-mapped I/O, and process syncrhonization facilities of the POSIX API in Linux.

What to submit

Submit your answer to each problem electronically using Git. For each problem, create in your Git repository a directory named with the problem's keycode, and upload to it all the relevant files for that problem (eg source code, Makefiles, READMEs, written explanations, etc).