scheduling program

how i can do that in c++ i can not know how i can start ?
Assume there are three (or any number) concurrent processes running on a system (with single CPU). These processes are needed to be scheduled for a period of time (pre-set or variable). Every task will run for the full slot (an allocated amount of time for a process) or finish its task before the slot finishes. E.g. If process A wants to run for 10 mS and the CPU slot is 50, then after 10mS (after completion of A), the CPU will move to the next process.

You are required to run the scheduling program for a certain amount of time and print a report to show some statistics such as, how long a certain process was executed, how many times etc.



this is my try code ?

#include <iostream>
using namespace std;
struct jobType{
int ID;
double Total;
double NextSchedule;
double jobDuration;
};
int main()
{
double MasterClock=0.0,T;
int N;
Type num[100];
n1,n2,n3 ;
n1.Total=0
n2.Total=0
n3.Total=0
n1.NextSchedule=1.5;
n2.NextSchedule=2.5;
n3.NextSchedule=3.5;

cout<<"How long you want to run the simulation: ";
cin>>T;

While(MasterClock<=T)
{

int NextJob=getNext(n1, n2, n3)
if(NextJob==1)
{
MasterClock=MasterClock+n1.NextSchedule;
num[NextJob].Total=n1.Total+n1.jobDuration;
MasterClock=MasterClock+n1.jobDuration;
//rescheduling
n1.NextSchedule=MasterClock+rand();
n1.jobDuration=rand();


}
if(NextJob==2)
{
MasterClock=MasterClock+n2.NextSchedule;
num[NextJob].Total=n2.Total+n2.jobDuration;
MasterClock=MasterClock+n2.jobDuration;
//rescheduling
n2.NextSchedule=MasterClock+rand();
n2.jobDuration=rand();

} else
{
MasterClock=MasterClock+n3.NextSchedule;
num[NextJob].Total=n3.Total+n3.jobDuration;
MasterClock=MasterClock+n3.jobDuration;
//rescheduling
n3.NextSchedule=MasterClock+rand();
n3.jobDuration=rand();
}


}
//display statistics
return 0;
}
closed account (48T7M4Gy)
So, what happens when you run it? Does it run? What results do yeou get? Are they what you expected? Indeed what did you expect.

Maybe enclose your code with code tags, use <> in the toolbox on the right tags and proper indentation and present your code in a professional manner.
Topic archived. No new replies allowed.