Write code that simulates a scheduler to schedule processes on two processing cores according to the Shortest-Job-First

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write code that simulates a scheduler to schedule processes on two processing cores according to the Shortest-Job-First

Post by answerhappygod »

Write Code That Simulates A Scheduler To Schedule Processes On Two Processing Cores According To The Shortest Job First 1
Write Code That Simulates A Scheduler To Schedule Processes On Two Processing Cores According To The Shortest Job First 1 (62 KiB) Viewed 12 times
Here is the starter code:
#include <stdio.h>#include <stdlib.h>#include <unistd.h> //Header file to use sleep().#include <pthread.h>int xx=0;int threads_num=0;int loop_count = 0;
// A normal C function that is executed as a thread.// Specified as argument in pthread_create()void *myThreadFun(void *varset){ int procID; procID = pthread_self(); // obtain theprocess ID of this thread printf(">>New thread %d started \n",procID); printf(">>threads_num in child is %d \n",threads_num); printf(">>Child %d can do some stuffhere... \n", procID); // for example, note that changes in xx arevisible from parent and other threads xx +=1; printf(">>xx in child %d is %d \n",procID, xx); // This thread is finished so decrement thecount of running threads threads_num--; return NULL;} // Thread code ends here
int main(){ pthread_t thread_id[10]; // Specify maxnumber of threads to be created while (loop_count < 5) { if (threads_num > 2) { continue;} // Do not create more than 3 threads at a time printf("---------\nParent iteration%d\n", loop_count); printf("Current threads_num %d\n",threads_num); printf("Before Thread\n"); threads_num++; pthread_create(&thread_id[loop_count], NULL, myThreadFun,NULL); // pthread_join(thread_id,NULL); // This will make the parent wait until childfinishes printf("After Thread\n"); printf("xx in parent is %d \n",xx);
loop_count++; } // End Parent loop sleep(5); // Wait for all the threads tofinish // or wait for the last child to join pthread_join(thread_id[loop_count], NULL); exit(0);}
Write code that simulates a scheduler to schedule processes on two processing cores according to the Shortest-Job-First algorithm. The scheduler should spawn children processes which represent the processing of a ready process on a hardware core. Since there are only 2 cores, there should never be more than two active children at the same time. Use input such as: ProcessID cpuBurst 0 10 10 1 2 3 4 5 6 4 20 15 5 10 The input may be provided manually or may be read from a file. Your program should output the scheduling sequence and compute the total completion time as well as the average wait time. For this assignment it is ok to sort the jobs according to burst times and then simulate FCFS. BUT, be careful: there are 2 cores not just one. This is an individual assignment and not a group one; everyone should do his/her own code. Make sure to prepare a report which to upload on Moodle by the deadline (required).
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply