Write a C/C++ program which reads in a list of process names and integer times from stdin/cin and simulates round-robin CPU scheduling on the list. Name the source file assign2.cpp. The input to the program is a list of lines each consisting of a process name and an integer time, e.g.
ProcessA 4
ProcessB 10
Read the list (without prompting) until end of transmission, EOF(^d). You should read the list and represent it in a linked list data structure. You are allowed to use STL classes, BUT DO NOT USE a vector. You should use the alarm system call to schedule a timer interrupt every 3 seconds and sleep (or usleep) to simulate the process running. Use time remaining on the process for the call to sleep. It's easiest if the interrupt handler sets a flag. A process with remaining time will be awakened in the alarm handler. If the quantum is the same or less than remaining time, it will wake up without the alarm. Upon returning from either sleep or the interrupt handler, update the time left by subtracting 3 seconds or the time remaining, depending if interrupted or not. Write a message saying how much time it has left to execute, i.e.
ProcessA 1
If the time remaining is greater than 0, return it to the end of the queue. If the process has no time left to execute, you should write a message saying this i.e.
ProcessA Finished
and delete the process from the linked list.
If there are no processes left to execute, write a message saying
No processes left
and terminate your program. Please following the specification EXACTLY.
When you finish your program, call it assign2.cpp and submit using the submitOS script. If you implement your program in multiple source files, you can submit both either together or separately using the script. Write a comment at the top of your code identifying your name, the date, the class and assignment, and a title and short description for the program.
[NOTE: If this is your first submission: Configure your environment by running ~harazduk/bin/configOS from your home directory. This will create a directory OSGradedLabs for me to place graded programs. It will also change your path to include my bin directory. You will then be able to use my script submitOS on your source file to copy it into the submissions directory. You will have to run bash or logout and login for it to take affect.]
Like all Unix commands, the g++ command has many options that you can use to control its behavior. You can type man g++ to view a very long list of all options and their descriptions. For now, please familiarize yourself with the following options to g++ command:
g++ assign2.cpp -o assign2
[harazduk@storm assign2]$ assign2
ProcessA 9 ProcessB 5 ProcessC 2 ProcessD 8 ProcessE 11 ProcessF 3 ProcessG 7 ProcessH 4 ^dProcessA 6 ProcessB 2 ProcessC Finished ProcessD 5 ProcessE 8 ProcessF Finished ProcessG 4 ProcessH 1 ProcessA 3 ProcessB Finished ProcessD 2 ProcessE 5 ProcessG 1 ProcessH Finished ProcessA Finished ProcessD Finished ProcessE 2 ProcessG Finished ProcessE Finished No processes left [harazduk@storm assign2]$
#include <iostream>
#include <list>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <string>
We will take a look at OpenMP in class today by looking at the omp-hands-on-tutorial.pdf. Using any of the examples in the slides or any problem that you want to try to parallelize, please create a file openmp.cpp with your example. Please make sure that it compiles on storm with the following compile line:
g++ openmp.cpp -fopenmp -o openmp
OpenMP is a set of compiler directives that generate the code for threads and thread management making it easier to parallelize programs. To use openMP directives, you must include omp.h in your program.
#include <omp.h>
All directives begin with the prefix directive '#' starting in column 1.
#pragma omp
The deck linked above is a tutorial. What I would like the class to do is to play with it a little. Two programs are given below: one uses the parallel for loop feature and the other uses some of the API to print the thread id in each thread and the master prints out the number of threads. Pick one or both or some other problem and type it in, build it and test it. If you are interested, start a pet project and try to get it to work. If not, fool around with the package a bit, then submit it. As with the linux.txt
file, every student submission will receive full credit. An exceptional job will receive extra credit.
submitOS assign2.cpp submitOS openmp.cppYou can then run command
verifyOS assign2.cpp verifyOS openmp.cppTo retrieve the file and verify that if the file has been submitted successfully. It should display the file you submitted back to you.
If you want to submit openmp.cpp and assign2.cpp at the same time, use the command:
submitOS assign2.cpp openmp.cppUnfortunately, verifyOS only works on one file at a time.
verifyOS assign2.cpp verifyOS openmp.cpp
NOTE: There are two errors that you may encounter. The first you can fix yourself: submitOS: command not found. Either you did not run ~harazduk/bin/configOS or you did but the change did not take affect. If OSGradedLabs directory exists in your home directory, then you it's the latter. Run bash on the command line alone and try submitOS again.
bashIf you encounter another error, send me an email with the error and I will fix it for you. You have finished assign2.