While programming a CPU Scheduling in ANSI C for a linux environment, I have not been able to calculate the wait time for each queued process. Basically, I need to run 20+ processes with 4 cpus, and measure the time it takes for each process, average time it takes, CPU consumption, etc.
Here is an analogy for the process that I am trying to code:
The image I drew was trying to simplify my problems…
but this is a first come first serve CPU schedualer,
counter A is the CPU burst, counter B is the Device Burst,
line 1 is Ready Queue, line 2 is Device Queue…
Till now, I’m able to output the tasks into an array, but for my assignment I need to find out how long it took for each of the people to wait, the turn around time for each processes, and their average times.
Each person struct have an “arrivalTime” and can be changed anytime
Each person struct also have an array of time required at each counter “timeRequired[]”, it’s alternating, index 0 is for counter A, index 1 is for counter B, index 2 is for A again.
Each person struct have an array pointer for the timeRequired[], “arrayPointer”
The picture I drew says seconds, but it is actually any unit of time, an integer number,
I don’t really need the actual time clock…
What I did so far is I created 2 thread function, 1 for counterA and 1 for counterB,
and when ever A finished serving a person in line, A will stuff the person to B line,
when ever B finished a person, it will stuff it into the A line.
I feel like everything is there for me already, but I really dont know what I need to do from here on to calculated their wait times…
Or is there a easier solution than using threads?
The professor gave us 2 files
the helper methods
[http://pastebin.com/qF7nQsUR%5D
the header file
I’d approach it this way:
Figure out how to encode the input. The program needs to have the input “person 1 needs…” available to it in some way.
These definitions can work:
Next, you need to keep track of where each person is at any time.
This structure can describe what a person’s doing now:
An array of these can describe what each is doing at any tie