Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You need to write a driver(main) program to test your data structures as follows. As a good program structure, the main program should be in

You need to write a driver(main) program to test your data structures as follows. As a good program structure, the main program should be in a separate le from the classes. Your program should rst print your name when it starts. 1. In the rst test, you make a pcb_table of 20 entries with PCB ID from 1 to 20. Assume the priority values range from 1 to 50, where the lower value means the higher priority, i.e. priority = 1 means the highest prority and 50 means the lowest. Assume in this test the process of PID i have its initial priority = i, i.e. the lower PID means higher priority. When you add a process to the ReadyQueue you should change its state in the pcb_table to READY; you should change its state to RUNNING if you remove a process from the ReadyQueue. Create a ReadyQueue q1. Then do the following tests. (a) add processes 5, 1, 8, 11 to q1. Display the content of q1 (b) remove the process with the highest priority from q1 and display q1. 1 (c) remove the process with the highest priority from q1 and display q1 (d) Insert processes 3, 7, 2, 12, 9 to q1 (e) One by one remove the process with the highest priority from the queue q1 and display it after each removal. 2. The second test evaluates the performance of your implementation. Use the ReadyQueue q1 and the pcb_table from the rst test. First randomly select 10 process from the pcb_table and add them into q1, but assign each process a random initial priority between 1 and 50. Then You need to repeat the following steps 1,000,000 times and measure the total time of running the loop. (a) Randomly decide to remove a process from or add a process to the ready queue with equal probability (50% chance). i. If choose to remove a process, remove the one with the highest priority from q1 using the removeHighestProc function. If there are more than one processes with the highest priority, it's your design option to choose which one. For example, you may choose one randomly or the one that was inserted into the queue the earliest. Notice only processes currently in the queue can be removed. If q1is empty, then no process should be removed. ii. If choose to add a process, select one process from the pcb_table that isn't currently in q1 and insert it into q1 using the insertProc function, with a random initial priority value between 1 and 50. If all processes in the pcb_table are already in q1, no process should be added. Measure the total time of running the 1,000,000 iterations and print out the nal content of the ReadyQueue (don't print in each of the iteration). Hint: You may use the UNIX gettimeofday function to measure the time. type man gettimeofday in a Unix shell to get more information or look it up online. You may run your program a few times and takethe average. In the report, you should present and discuss your timing results.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago