Input1.txt: In this session, you will set up your account to implement necessary
ID: 3889238 • Letter: I
Question
Input1.txt:
In this session, you will set up your account to implement necessary linked list functions for FIFO CPU scheduling and perform the very basic steps in context-switching. In the next session, you will extend this program to implement other three basic CPU scheduling algorithms (namely, SJF, PR, and RR with a given quantum). To keep it simle, we assume each process has a single CPU burst without any IO burst and that all processes arrive at the same time in a given order. The order of es will be given in a simple input file. Each line in the input file consists of three integer numbers: Process Id, Process Priority, CPU Burst time (ms). Download inputLtxt as a sample input file Your program will take the name of the scheduling algorithm, related parameters (if any), and an input file name from command line. In general, here how your program should be executed: > prog -alg [F1FOISJFPRIRR] [-quantum [integer(ms)]] -input [input file-name . txt] In this session, you will just run it as prog -alg FIFO -input input1.txt For the given input file, the output of your program will be as follows: Student Name: Your name Input File Name input1.txt CPU Scheduling Alg FIFO Proces 1 is completed at 5 ms Proces 2 is completed at 12 ms Proces 3 is completed at 18 ms Proces 4 is completed at 22 ms Average waiting time = 8.75 ms (35/4) Average Turnaround time 14.25 ms (57/4) Throughput .18 jobs per ms (4/22)Explanation / Answer
struct PCB* handleProcessArrival_PP(struct PCB *processhead,struct PCB *processtail,struct PCB *currProcess,struct PCB *newProcess,int currTime){
if(currProcess==NULL){
newProcess->executionStartTime = currTime;
newProcess->executionEndTime = currTime+newProcess->totalBurstTime;
newProcess->remainingBurstTime = newProcess->totalBurstTime;
if(newProcess->processID==processhead->processID){
processhead= newProcess->next;
printf("processhead in case 1 %d ",processhead->processID);
}
currProcess=newProcess;
printf("***current process = new process%d ",currProcess->processID);
contents(processhead);
return currProcess;
//return processhead;
}
if (currProcess->processID !=0){
contents(processhead);
if(currProcess->processPriority>newProcess->processPriority){//new process higher priority
printf("***new process in handle %d ",newProcess->processID);
currProcess->executionStartTime = 0;
currProcess->executionEndTime = 0;
currProcess->remainingBurstTime = currProcess->totalBurstTime-(currProcess->executionStartTime-currTime);
processtail->next=currProcess;
processtail=currProcess;
newProcess->executionStartTime=currTime;
newProcess->executionEndTime = currTime+newProcess->totalBurstTime;
newProcess->remainingBurstTime = newProcess->totalBurstTime;
currProcess=newProcess;
printf("current process replaced with%d ",newProcess->processID);
printf("processhead in case 2 %d ",processhead->processID);
return currProcess;
}
if(currProcess->processPriority<newProcess->processPriority){//new process lower priority
contents(processhead);
newProcess->executionStartTime = 0;
newProcess->executionEndTime = 0;
newProcess->remainingBurstTime = newProcess->totalBurstTime;
processtail->next=newProcess;
processtail=newProcess;
printf("new process in handle %d ",newProcess->processID);
printf("current process continues%d ",currProcess->processID);
printf("processhead in case 3 %d ",processhead->processID);
return currProcess;
}
}
/* printf("process id = %d ",currProcess.processID);
printf("arrival time = %ld ",currProcess.arrivalTimeStamp);
printf("total burst time = %ld ",currProcess.totalBurstTime);
printf("start time = %ld ",currProcess.executionStartTime);
printf("end time = %ld ",currProcess.executionEndTime);
printf("remaining burst time = %ld ",currProcess.remainingBurstTime);
printf("priority = %d ",currProcess.processPriority);
*/
}
struct PCB* handleProcessCompletion_PP(struct PCB *processhead,int currTime){
if (processhead==NULL){
return NULL;
}else{
contents(processhead);
printf("in else processhead is %d ",processhead->processID);
struct PCB *processtemp;
processtemp=processhead;
int len=length(processhead);
struct PCB *procArray[len];
int i=0;
printf("test");
while(i<len){
procArray[i] = processtemp;
printf("process put in array %d",procArray[i]->processID);
processtemp=processtemp->next;
i++;
}
int min =0;
for(i=0;i<len;i++){
if(procArray[min]->processPriority > procArray[i]->processPriority){
min = i;
}
}
printf("high priority process %d",procArray[min]->processID);
procArray[min]->executionStartTime = currTime;
procArray[min]->executionEndTime = currTime+procArray[min]->remainingBurstTime;
procArray[min-1]->next=procArray[min+1];
printf("process to run next is %d",procArray[min]->processID);
return procArray[min];
//return processhead;
}
}