CS 377: Operating Systems - Lab 1

Due: Tuesday, October 13 @ 5 pm

UMass Computer Science, Fall 2015 [Course homepage]


The purpose of this lab is to give gain some experience working with system calls and learn about process management (process creation, termination etc). In this lab, you will write C programs making use of several UNIX system calls. You will also need to write a design document explaining how your program(s) are organized (details below).


Part 1: Process Creation

This component of the lab requires you to use the fork system call. Write a program using fork() where a parent process creates a child process and a child process creates a grand-child. The grand-child process sleeps for 10 seconds and exits after printing "Grandchild process with process id [PID] has completed." The child process should wait for the grand-child to finish and once it does so, it should exit after printing "Child process with process ID [PID] has completed." The parent process should wait for the child process to finish and then exit after printing "Parent process with process ID [PID] has finished.

A process may use the waitpid() system call to wait on a process and the getpid() call to obtain its own process ID.

Be sure to read the manual ("man") pages for these system calls to understand how to use them in your program. These are also available online here

Part 2: Process termination

Write a program that functions as a process termination utility (which we will refer to as the kill utility). Your program should prompt the user to enter a process id and then use the kill system call to terminate it. Be sure to handle error cases carefully, including errors where the user does not have privileges to terminate the specified process, or the user specifies an non-existent process. The return values from the kill system calls will indicate whether the call succeeded or what type of error occured.

Part 3: Batch Scheduler

The last component of the lab involves writing a batch scheduling shell. This shell program takes as input a sequence of batch programs to run. The shell then runs these programs sequentially one after another. This is done by forking a child process and having it use exec to run the specified program. The parent shell process waits for the child to finish and then runs the next program in a same fashion.

Your batch program should be able to take an arbitrary list of programs from the command line and then run them one after another.

user@elnux2$ ./batch-shell
batch-shell> program1 program2 program3 program4
  output of program1
  output of program 2
  output of program 3
  output of program 4
batch-shell> quit
user@elnux2

Additionally, each new process your program creates should print its process ID before executing the command, as well as any other output you would like that demonstrates how your program is operating.

Tips



Design Document and Observation

Once you have written code for all three parts, write a design document that documents your design choices. In addition to the design document, write detailed comments in the source code to explain your code.

How to Turn in Lab 1

All of the following files must be submitted on Moodle as a zip file in the form FirstnameLastname.zip to get full credit for this assignment.

  1. Include a copy of all source files.
  2. Include a README file containing an outline of what you did. It should also explain and document your design choices. Keep it short and to the point. If your implementation does not work, you should document the problems in the README, preferably with your explanation of why it does not work and how you would solve it if you had more time. Of course, you should also comment your code. We can't give you credit for something we don't understand!
  3. Finally, include a file showing sample output from running your program.
  4. Note: Please make sure you turn in your own work. We will strictly enforce policies on cheating. Remember that we routinely run similarity checking programs on your solutions to detect cheating.

    You should be very careful about using code snippets you find on the Internet. In general your code should be your own. It is OK to read tutorials on the web and use these concepts in your assignment. Blind use of code from web is strictly disallowed. Feel free to check with us if you have questions on this policy. And be sure to CLEARLY document any Internet sources/ tutorials you have used to complete the assignment in your README file.

    We will check and flag snippets of code borrowed from various internet sites, so be sure to write your own code.



Lab 1 Grading Scheme

(max 100) Total Grade

Late Policy: Lab 1 is due at 5 PM on Tuesday, October 13. Please refer to the course syllabus for late policy on lab assignments. This late policy will be strictly enforced. Please start early so that you can submit the assignment on time.