my desired output is this:

Input number of process to simulate SJF: 4
Input burst time for each process:
P1 = 7
P2 = 4
P3 = 1
P4 = 4

Input Arrival Time for each process:
P1 = 0
P2 = 2
P3 = 4
P4 = 5


Now simulating SJF:

Time Process Running

1 P1
2 P1
3 P1
4 P1
5 P1
6 P1
7 P1
8 P3
9 P2
1O P2
11 P2
12 P2
13 P4
14 P4
15 P4
16 P4

Waiting Time:

P1 = 0
P2 = 6
P3 = 3
P4 = 7

Average Waiting Time = 4


--------------------------------------------
is any one familiar with non preemptive SJF?


i'm having a problem computing for the waiting time for each process given the arrival time and burst time. Also, the time process running part, i really don't have a clue what
to do.. does anybody have an idea?

I have attached my full code.

Recommended Answers

All 3 Replies

I could be way off base here but could you not just have a management process of some kind. This process would keep track of the remaining execution time of the currently running process plus those that haven't been executed yet. For each process waiting, the management process could calculate the time for all processes that will be executed before the process for which the waiting time is being calculated.
e.g. if p1 is currently running then (based on burst time) the next to execute is p3. p4 and p2 have the same burst time so the first to execute will be whichever arrived first. Now you know the order of execution you can calculate that, lets say p2, will have to wait for the remainder of p1's execution (burst time) plus that of p3 because these will both run before p2.

what do you mean manage process of somewhat sir?
I'm thinking of an array, its length as total burst time.. den the first array would be occupied the process 1.. 0-6.. since p1's burst time is 7... is that wat u min?

Well there are multiple solutions so yes an array could be used I guess. If you store the processes in the order in which they will run then you can calculate the wait time of each process based on the processes stored before.
e.g. the process stored in array index 2 would have a wait time equal to the burst time of index 0 plus index 1.

The limitation to using an array is that you would have to know the number of processes that will be run, prior to creating the array, so that enough memory can be allocated. Otherwise you will need to allocate memory dynamically which would be costly if processes are continually being added to and removed from the array.
A vector may provide a similar but tidier solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.