I think this has something to do with process scheduling.

(1st process)

Start 0// starts at 0ms
Run 10 // runs for 10 ms
Disk 0 // no idea what this does, but it takes 10 ms
Run 30 // run 30 ms
End // terminates

(2nd process)

Start 5
Run 20
Disk 1
Run 40

Ok, So I read it from the text file using ifstream and put it into a linked list. I think this is an intro to multiprogramming. You start, move to Run 10, then it runs for 10 ms. While it runs, you move to the next start and check when it starts and move the run 20 into a queue, which tne moves into the CPU once the first 10 ms is finished. Not sure what the "disk" does here, though.

Question is: What do I do once it's in the linked list? How do I move to the second process and then back and forth ? I can't put it all in a queue at once. It goes in there one after another. Obviously, many processes start while one is still in the CPU. So they have to wait until the previous one is finished. It's just a simulation, of course. I think it will print out a report telling you how much time has elapsed etc. Is anybody familiar with this? I'm very confused about this.

So the start denotes that the particular process should be executed after [param] ms has passed, correct? So as the 1st process executes, after 5 ms of its execution(in the middle of run 10), it will run 'along side with' the second process which was due to run after 5 ms of execution. Okay.

I think we could simply add up the time each process has and treat the process as a single unified entity needing x ms time for execution. So let's read those processes in the text file and parse it and put it in a struct

struct Proc {
    int start;
    int run; // run + disk + run
    struct Proc *next;

Which would be sorted in ascending order of start and the program will run something like

void runall(Proc *list){
    Proc *parallel;
    while(list not empty){
        insert first node of list to parallel (reduces list, adds parallel)

        run_processes_until(parallel, list->start) // runs until list->start has elapsed
        // could also kill processes and reduce parallel when it needs to

        // when list->start elapsed, will exit function, then it is time to execute another process, next loop iteration

Of course, there should be checks for when list is empty already (e.i. last process on queue). How the processes run in parallel doesn't matter, I guess, for the sake of simulation; you could decrement run for the sake of simulation.

I hope it was helpful.

I have this impression that it works like magic in the OS instead of this brute solution. :(

This article has been dead for over six months. Start a new discussion instead.