Lab Exercise 2 Hints Revision 1

Below, one important point about how long a process blocks for I/O is omitted. If there are 0 time units left on the run time, set the length of time for the I/O to block to 1 time unit. Do not generate a random number for this.

The goal of this document is to give you some help with Lab Exercise 2. You are free to use them or ignore them.

Reading the Input File

This will be argv[2]. Each line consists of a string of alphanumerics (in particular, no blanks), some tabs or blanks, an integer, and a floating point number. These are:

As you read each line, you should add each process to the end of the ready queue.

Execution of Simulation

The simulation has 2 parts: managing the CPU and ready queue, and managing the I/O device and I/O queue. Let’s look at these separately.

CPU and Ready Queue

You can either have a special pointer for the CPU so that, when a process executes, it is removed from the ready queue and placed on the CPU. You could also have the first process in the ready queue be on the CPU and on the ready queue, so the pointer to the head of the ready queue is also the CPU.

A process that enters the system or blocks due to a quantum or for which the I/O ends for that process goes onto the end of the ready queue.

When a process is moved to the CPU, the time to next block is reset.

To simulate the CPU, proceed as follows:

I/O Device and I/O Queue

When a process is moved to the I/O device, proceed as follows:

To simulate the I/O, proceed as follows:

Putting These Together

Every process starts on the ready queue, so it makes sense to start with the CPU, and then the I/O device, and continue until there is nothing on the CPU, I/O device, and both queues.

Every process ends on the CPU, not on the I/O device, so even if both the remaining run time and the remaining I/O time are 0, you must move the process to the ready queue. When it gets the cpu, it then terminates.

Some Things You Might Find Useful

Random Number Generation

You have to produce the same random numbers, in the same order. To test this, a program called prsim-rand is in the CSIF directory ~bishop/ecs150-lab2. In addition to the normal output (what prsim generates), it lists the random numbers as integers), then one of the following:

This may help you figure out why you are getting different results from the ones generated by prsim.

Formatting Your Output

The program output produces bogus output, but it’s formatted correctly. It shows both output and error messages. You are welcome to copy those output print statements and modify them for your program. Just be sure to leave the string part as is!


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
ECS 150, Operating Systems
Version of May 28, 2022 at 9:27PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh