Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to read a binary file into struct array and perform rr,fcfs,priority,and

ID: 3534302 • Letter: I

Question

I need to read a binary file into struct array and perform rr,fcfs,priority,and sjf. Need to calculate the average waiting time for the set of processes. Most importantly, I need help reading data into the single processes array. Need help with one of these methods or all. Can all be done in main.

file looks like:

Proc ArrivalTime Burst Priority Waiting

p1 0 10 3 0

p2 0 1 1 0

p3 0 2 3 0

p4 0 1 4 0

p5 0 5 2 0



//header file:

struct process

{

int pid; // process ID

int arrival; // arrival time

int burst; // CPU burst time

int priority; // process priority

int waiting; // waiting time (initially 0)

};

//.cpp file to read in binary file and perform rr,fcfs,priority, and sjf (needs work)


#include <process.h>

#include <cstring>

#include <stdlib.h>

#include <io.h>

#include <fcntl.h>

#include <sys/stat.h>

#include <error.h>

#include <iostream>

using namespace std;


int id_comp(const void* ind1, const void* ind2);

struct process *processes[10];

int bin_fd; // binary file descriptor

int main(int argc, char* argv[])

{

if ((bin_fd = _open(argv[1], _O_BINARY | _O_RDONLY )) < 0)

{

cerr << "Unable to open binary file ";

exit(1);

}

int count = 0;

while (_read(bin_fd, &processes[count], sizeof(processes)) > 0){

count++;

}

qsort(processes, count, sizeof(processes), id_comp);

Explanation / Answer

Yes, All can be don in main.

Cheers