You are on page 1of 61

1



(READY)
1







2


:





,


/ ,


-


,

4

e (, admission)
 ,


;
 (
)



()
 (time-sharing)
 ().

 swapping

()
 ,
5


(job queue)


(ready
queue)

- (I/O
queue)


:








,


/ ,

- ..



.


:

( )

( )


10

(Responsiveness)
Job 1
arrives

Job 2
arrives

Job 3
arrives

Job1

Job2
Job 1
terminates

Job1

Job3
Job 2
terminates

Job 3
terminates

Job3
Job2
Job 1 terminates

Job 3
terminates

Job 2 terminates
11

(Utilization)
I/O
2nd I/O
ends operation

1st I/O
operation

CPU

idle

idle

Disk

idle

CPU

Job1

Disk

idle

idle

idle
idle

Job1 idle

Job2
Job1

3rd I/O
operation

I/O
ends

idle

Job2

Job2
Job1

idle

12

(CPU utilization) (
)

(throughput) (
)

(turnaround
time) (

)

(waiting time) (

)

(response time) (
)
13

-
terminated
running
schedule
created

wait for event

preempt
ready

blocked
event done

14

-



/
ready
(run)

ready

15

(nonpreemptive)
(Windows 3.1)




(/

)

16

(preemptive)


,

()
(/
)



, ,

(context switching)
( ,
)

17

: Twait


- Throughput


18

:
(Response time)



- Tresp

Job arrives/
becomes ready to run

Starts running

Job terminates/
blocks waiting for I/O

Trun

Twait
Tresp
Tresp= Twait + Trun

19

:
 = (
/ )
 = ( )
:
,
.

:
 First come, first served (FCFS)
 Shortest Job First (SJF)
 Shortest Time Remaining Next (STRN)
 Round Robin (RR)
20

21


(FCFS)







,


, /
-
/
FCFS (
/) ( )
22

(SJF)






( )

, FCFS
23





STRN Shortest Time Remaining Next


SFJ

,
(.2 .3)

24

(Round-robin)




FCFS (preepmptive)



(10 100 m sec)

25


( ) :

26


(PS)


SJF PS

. ,
, ,
(, /);
( ,
)
27


(PS)


: 1/f f

 -

( )
RR

(,
)
, ..
( aging)

28


(multiple queues)


, - ,

29


(multiple queues)

 100
.


1 ,
, 2 , 4,8,16,32,64,
37 .

7
100 RR-
30


(Aging)


Tn n-
( , - recent history),
Fn+1
(Fn past
history)

:
Fn+1= Tn + (1- ) Fn,

(
)
31


(Aging)


:

, T0 i T1
F1=T0, F2= T1 + (1- ) F1,
FK = TK-1 + (1- ) FK-1, K=3, 4, ...
= 1/2 ( )
T0, T0 /2+T1/2, T0 /4+T1/4+ T2/2, T0 /8+ T1/8 + T2 /4+ T3/2,...
( )

SJF ( )
,

32


(Lottery scheduling)



(. ).

100 20
20%



33


(Fair-Share Scheduling)


.

(. 2 , 1 1 , 9)

1: A,B,C,D

RR 50% :
 A E B E C E D E A E B E C E D E

1 2-
:
 A B E C D E A B E C D E




2: E

34


Real Time





:
 Hard time (
)
 Soft time (
, )



 ( )
 ( )

:
m

Ci
1

i =1 Pi


m , i
Pi Ci
35

:





(FCFS, SJF, RR, )
( )
,
.

:




- ,


36





50-msec
5 msec/CPU burst
37





50-msec
5 msec/CPU burst
38

UNIX


,
,


fork(), exec(), wait(), exit()

kill()

ptrace(), nice(), sleep()

39

fork() - UNIX


-


:



( )

( )
40

fork() - UNIX


( )

fork():



- , fork() 0 (PID )
- , PID 0

fork():



-

-
!
41

fork()


- :
main()
int pid = fork();
if (pid == 0)
{
}
else
{
}




// create a child
// child continues here

// parent continues here

42

exec()


exec()

(argc)
(argv)

 !!
 !!
:
 exec()
( .
/bin/ls )
 ,
, )

43

exec()


- :
main()

int pid = fork();


// create a child
if (pid == 0)
{
// child continues here
exec(program, argc, argv0, argv1, );
}
else {
// parent continues here

99% , xec() fork()

44

: exit()


,
exit()

:









, .



:

,
zombie/defunct
45

:
 nice, ( )
 UNIX -

:
 ptrace,

 ,
, .

:
 sleep
, at
46

(

):


,

0

47

(
):
 <Ctrl-C>,


, kill -9

(trap UNIX):

 ()
 (
)

48





.
init

.

,

: ,

49







:
 inetd
 atd
 Nfsd

50


( ) 1


, CPUburst (u msec) :







Process
P1
P2
P3
P4
P5

Burst Time
10
1
2
1
5

Priority
3
1
3
4
2


0 P1, P2, P3, P4, P5


a) Gannt-
FCFS, SJF, non-preemptive priority (
), RR (quantum=1)
b) tournaround

c)

d)
51

FCFS
Process
P1
P2
P3
P4
P5

a. Turnaround time
TA(P1) = 10
TA(P2) = 11
TA(P3) = 13
TA(P4) = 14
TA(P5) = 19
TAavg = 13.4

Burst Time
10
1
2
1
5

Priority
3
1
3
4
2

b) Waiting time
W(P1)=0
W(P2)=10
W(P3)=11
W(P4)=13
W(P5)=14
Wavg=9.6
52

RR=1
Process
P1
P2
P3
P4
P5

a.
Turnaround time
TA(P1) = 19
TA(P2) = 2
TA(P3) = 7
TA(P4) = 4
TA(P5) = 14
TAavg = 9.2

Burst Time
10
1
2
1
5

Priority
3
1
3
4
2

b) Waiting time
W(P1)=4+2+1+1+1=9
W(P2)=1
W(P3)=2+3=5
W(P4)=3
W(P5)=4+2+1+1+1=9
Wavg=5.4
53

Priority
Process
P1
P2
P3
P4
P5

a. Turnaround time
TA(P1) = 16
TA(P2) = 1
TA(P3) = 18
TA(P4) = 19
TA(P5) = 6
TAavg = 12

Burst Time
10
1
2
1
5

Priority
3
1
3
4
2

b) Waiting time
W(P1)=6
W(P2)=0
W(P3)=16
W(P4)=18
W(P5)=1
Wavg=8.2
54

SJF
Process
P1
P2
P3
P4
P5

a. Turnaround time
TA(P1) = 19
TA(P2) = 1
TA(P3) = 4
TA(P4) = 2
TA(P5) = 9
TAavg = 7

Burst Time
10
1
2
1
5

Priority
3
1
3
4
2

b) Waiting time
W(P1)=9
W(P2)=0
W(P3)=2
W(P4)=1
W(P5)=4
Wavg=3.2
55

2


4 t=0
ready-queue
burst-time .






Process
P1
P2
P3
P4

Burst Time
6
3
1
7

RR quantum=7, Gannt-
turnaround

contex
switch=0.01 4
?
56

RR=7
Process
P1
P2
P3
P4

a. Turnaround time
TA(P1) = 6
TA(P2) = 9
TA(P3) = 10
TA(P4) = 17
TAavg = 10.5

Burst Time
6
3
1
7

b) Waiting time
W(P1)=0
W(P2)=6
W(P3)=9
W(P4)=10
Wavg=6.25

Ttotal = Tprocesses + NxTcsw=17+3*0.01=17.03


57

RR=2

Process
P1
P2
P3
P4

a. Turnaround time
TA(P1) = 14
TA(P2) = 10
TA(P3) = 5
TA(P4) = 17
TAavg = 11.5

Burst Time
6
3
1
7

b) Waiting time
W(P1)=0+5+3=8
W(P2)=2+5=7
W(P3)=4
W(P4)=5+3+2=10
Wavg=7.25

Ttotal = Tprocesses + NxTcsw=17+9*0.01=17.09

58

3









turnaround SJF
STRN
Process
P1
P2
P3
P4

Arrival Time
0.0
2.0
4.0
5.0

Burst Time
7
4
1
4

59

SJF
Process
P1
P2
P3
P4

Arrival Time
0.0
2.0
4.0
5.0

Burst Time
7
4
1
4

a. Turnaround time
b) Waiting time
TA(P1) = 7
W(P1)=0
TA(P2) = 12-2=10
W(P2)=8-2=6
TA(P3) = 8-4=4
W(P3)=7-4=3
TA(P4) = 16-5=11
W(P4)=12-5=7
TAavg = 8
Wavg=4
Ttotal = Tprocesses + NxTcsw=16+3*0.01=16.03
60

STRN
Process
P1
P2
P3
P4

a. Turnaround time
TA(P1) = 16
TA(P2) = 7-2=5
TA(P3) = 5-4=1
TA(P4) = 11-5=6
TAavg = 7

Arrival Time
0.0
2.0
4.0
5.0

Burst Time
7
4
1
4

b) Waiting time
W(P1)=0+9=9
W(P2)=0+1=1
W(P3)=0
W(P4)=7-5=2
Wavg=3

Ttotal = Tprocesses + NxTcsw=16+5*0.01=16.05

61

You might also like