The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+24 votes
  1. Four jobs are waiting to be run. Their expected run times are $6, 3, 5$ and $x.$ In what order should they be run to minimize the average response time?
  2. Write a concurrent program using $\text{par begin-par end}$ to represent the precedence graph shown below.

in Operating System by Veteran (52.1k points)
edited by | 2.7k views
there is difference between par begin par end and co begin end???

3 Answers

+22 votes
Best answer
  1. Here, all we need to do for minimizing response time is to run jobs in increasing order of burst time.
  2. Schedule shorter jobs first, which will decrease the waiting time of longer jobs, and consequently average waiting time and average response time decreases.

  3. $6, 3, 5$ and $x.$

    If $X < 3 < 5 < $6,  then order should be $x,3,5,6$

    If $3 < 5 < 6 < x$, then order is $3,5,6,x$.

    If $3 < x < 5 < 6$, then order is $3,x,5,6.$  If $5 < x < 6$, then order is $3,5,x,6.$


Idea is that if you have $S_1 \to S_2$ then you create new semaphore a, assume that initial value of all semaphores is $0$. Then $S_2$ thread will invoke $P(a)$ & will get blocked. When $S_1$ get executed, after that it'll do $V(a)$ which will enable $S_2$ to run. Do like this for all edges in graph.
Let me write program for it.


Semaphores $a,b,c,d,e,f,g$

ParBegin $ S_1 V(a) V(b) V(c) V(d)$ Parend
ParBegin $P(a) S_2 V( e)$ Parend
ParBegin $P(b) S_3 V(f)$ Parend
ParBegin $P( c) P( e) S_4 V(g)$ Parend
ParBegin $P(d) P(f) P(g) S_5$ Parend

IF you reverse engineer this program you can get how this diagram came.

Parbegin Parend – Parallel execution

$P-$ Down, $V-$ Up

by Boss (41.1k points)
edited by
co and par are same ?? what is meaning of co
co - concurrent

par-  parallel

I think they are same.
ok... par begin p(g)p(f)p(d) s5 rt ?
okay now ?

I think u have misplaced/interchanged the use of Parbegin & begin here..Becoz

ParBegin  S1 V(a) V(b) V(c) V(d) Parend        


ParBegin P(a) S2 V( e) Parend   

  can execute parallely .But u hv placed them inside begin meaning they execute one by one..

As it is not mentioned that algoritm must be non preemptive so Round Robin with TQ = 1 is the best approach here.
@Akash , What is the use of c and d semaphore here? I think you have used them because of the edges in the precedence graph s1 to s4 and s1 to s5. But are not these extra (I mean unnecessary)?
@ Akash Kanase, @Bikram Ballav Sir, @Hemant Parihar, I feel Himanshu 1 says it correct. Could you please crosscheck it once.

I too think the same.

Is this code right?

Please tell book or online source for learning and practising precedence graph questions
+4 votes
24) a. It will depends on value of x.. U can decide others 3 process sequence I.e 3,5,6 Now x can come anywhere depending on its value.. Remember we shld gve it in increasing order to minimize response time
by Active (2.3k points)
–3 votes
The average response time depends upon the value of x

if x < 3

then the order is x,3,5,6

if the value of x >3 and x < 5

the the order is 3,x,5,6

if the value of x > 5 and x < 6

then the order is 3,5,x,6,

if the order > 6

then the order is



For the second question it will be S1---S2---S3---S4---S5  OR S1---S3----S2----S4----S5
by Active (1k points)
I have doubt..

Response time is defined as the time taken from submission of request to the first response by the CPU.

So, cant we just use round robin with time quantum = 1. This way each process will use the cpu for the first time after (0,1,2,3) secs respectivly..! Making the average response time = (0+1+2+3) / 4.
@Harsh181996 I do think the same. Because minimum average time is always obtained by Round Robin and it is nowhere mentioned in question that the algorithm is non-preemptive.

Above answers are valid only when algorithm is supposed to be non- preemptive


what will be the value of x by this ?

Whatever be the value of x, the avg. response time will not change if we do RR scheduling with time quantum 1.

It is very valid question put up by Harsh181996 but I think if we had used the round robin algo then there wouldn't have been any interest in finding the order of execution of the processes as any order will give the same average RT. So the purpose of the question might get lost. 

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,807 questions
54,729 answers
79,912 users