Professional Documents
Culture Documents
3102
operatingsystem13@gmail.com :
()2
....
.
.
.
:
.
.
()3
.
.
.
.
operatingsystem13@gmail.com
()4
3..............................................................................................
: 33.............................................................................
.3.3 31 ............................................................
.3.1 31 .....................................................................
.3.3 31 ..................................................................
.3.1 31 .................................................................
.3.1 31 .................................................................
.3.1 13 ...................................................................
.1.6.1 32.............................................................................
1.6.3 (32......................................................)multiprogramming
.1.6.2 (32........................................................ )Time-sharing
.3.1 11 ...............................................................
.3.1 11 ................................................................
.1.8.1 32............................................ Mainframe Systems
.1.8.3 32...............................................................................
.1.8.2 (38.......................................... )Multiprocessor
.1.8.2 32...................................................................................
.1.8.1 (32..............................................)Clustered Systems
.1.8.6 (23................................................ )Real-time
.1.8.2 (21................................................................. )hand held
.1.8.8 (23............................................... )Emedded Systems
.1.8.2 (23.................................... )Smart card Systems
.3.1 33 .................................................................................
.3.31 31 ......................................................................
.3.33 31 .................................................................
()5
: 11.................................................
.1.3 (11 .................................................. )computing
.1.1 11 ........................................................................
.1.3 (11 ........................................................ )Interrupts
.1.1 11 ...................................................... dual mode
.1.1 11 ....................................................................... timer
.1.1 11 .........................................................................
.1.1 11 ..............................................................
.3.2.1 16....................................................................
.3.2.3 12........................................................................................
.1.1 11 ....................................................................
.3.8.1 (12...............................................................................)Booting
.3.8.3 12.........................................................................
.1.1 13 .................................................................................
.1.31 11 ......................................................................
.1.33 13 .................................................................
: 11........................................................................
.3.3 11 ..................................................................................
.3.1 (11 .......................................... )Process Concept
.3.3 (11 ............................................. )process states
.3 .1 11 .........................................................................
.3.1 11 ..........................................................................
.3.1 11 ..........................................................................
.3.1 )11 ................... Process Control Blocks (PCB
()6
.3.1 11 ..................................................................
.1.31 11 .................................................................
3.33 13 ................................................................
.3.31 11 ......................................................................
.3.33 11 .................................................................
: 11.................................................................
.1.3 (11 ............................... )CPU I/O Burst Cycle
.1.1 11 ........................................................................
.1.1 (11 .................................... )Scheduling Criteria
.1.1 13 ..........................................................................
.1.1 (13 ........................ )Scheduling Algorithms
.2.1.1 (22................................. )First-Come, First served
.2.1.3 )21....................................Shortest-Job-First (SJF
.2.1.2 (133............................................................................ )Priority
.2.1.2 ()133................................................. )Round Robin (RR
: 331...............................................................
.1.3 331 .................................................................................
.1.1 331 ........................................................................
.1.3 331 ........................................................................
.1.2.1 (118............................................................ )user thread
.1.2.3 112.........................................................................................
()7
.1.2.3 131.................................................................................
: 331.....................................................................
.1.3 331 ................................................................................
.1.1 331 ............................................... Concurrency
.1.3 331 ......................................................................
.1.1 (331 ........................................................ )competition
.1.1 331 .........................................................
.6.1.1 (123..................... )reading and writing problem
.6.1.3 (123.................................. )producer-consumer
.6.1.2 (128...................... )Dining philosophers problem
.6.1.2 (111.......................)Cigarette smokers problem
.6.1.1 112.......................................................................... Rendezvous
.6.1.6 (112............................................... )sleeping barber
: 311......................................................................
()8
.1.3 (311 .................................................... )resource
.1.1 311 .....................................................................
.1.3 311 ........................................................................
.1.1 313 ....................................................................
.1.1 311 .................................................................
.1.1 313 .................................................................
.1.1 (311 .................. )Banker's algorithms
: 311.....................................................
.1.3 313 ...............................................................
.1.1 311 .................................................................
.1.3 311 .........................................................
.1.1 311 .......................................................................
.1.1 311 ...................................................................
.1.1 111 ........................................................
.1.1 111 .........................................................
.1.1 111 .......................................................................
.1.1 111 ..................................................................
.1.31 133 ................................................................
.1.33 (131 ............................... )Logical addresses
.1.31 (111 .................................................. )Paging
.1.33 (111 ................................................ )segementation
.1.31 131 .............................................................................
.1.31 133 ....................................................................
()9
.1.31 131 ...............................................................
: 131............................................................
.1.3 113 ..........................................................................
.1.1 113 ............................................................
.1.3 111 ............................................................. Swapping
.1.1 111 ....................................................................
.1.1 113 .....................................................
.1.1 111 .....................................................
.1.1 ( ) 111 ..............................................
.1.1 111 ......................................................................
.1.1 113 .................................................................
: 111...............................................................
.31.3 111 ..............................................................................
.31.1 111 .............................................................
.31.3 (111 ........................................................ )controller
.31.1 ()111 .... )Direct Memory Access (DMA
.31.1 111 ..............................................................
.31.1 113 ..................................................
.31.1 111 ..............................................................
.31.1 (111 ............ )I/O software layers
.31.1 111 ....................................................................
.31.31 111 ...................................................................
.31.33 111 ............................................................
()01
.31.31 111 ..................................................................
.31.33 111 .............................................................
: 111........................................................
.33.3 111 ..............................................................
.33.1 111 ......................................................................
.33.3 (111 ........................................... )File Attributes
.33.1 111 .............................................................
.33.1 311 ......................................................................
.33.1 311 ........................................... access method
.33.1 311 ....................................... Directory structures
.33.1 313 .............................................................................
.33.1 311 ......................................................................
: 331........................................................
.31.3 331 ..............................................................................
.31.1 331 ....................................................
.31.3 331 ...............................................................
.31.1 (333 ..................................... )DSM
.31.1 )331 .... Network Operating System (NOS
.31.1 331 .............................................. middleware
.31.1 311 .............................................................................
311.......................................................................................
311 ....................................................................................
311 ................................................................................
()00
311 ...............................................................................
( ) 311 .....................................
1.31 311 ................................................ 1.11
()02
()03
()04
( )hardware
( .)software
.
( ) .
.
.
.
.0.0
( )
.
.
(
).
.
()05
( :)0-0
:
(.)0-0
.
.
:
.
.
.
.
.
()06
.0.2
.
DOS
.
.
.
( .)3-0
( :)3-0 .
()07
.0.3
.
( )user interface
.
.0.2.0 :
.
(.)convenient
(.)efficient
.0.2.3
(:)resources
.
(:)user interface
( .)user interface
( ) )graphical user interface (GUI
.
:
(
).
:
( )allocate ( )free
.
:
(
)
.
()08
:
.
.0.2.2 :
.
.0.4
( )media player
! . :
( )kernel
.
.
.0.5
( )
:
(.)computer hardware
(.)kernel
( .)operating system interfaces
( .)applications
(.)user
()09
.0.5.0
.
.0.5.3
. :
.
.
.
.
.
.
.0.5.2
.
:
(.)GUI
( )shell (.)command line interpreter
( .)system call interface
.0.5.2.0
.
()21
.
X-Window .
.
.
.0.5.2.3
()
.
.
.0.5.2.2 System call
( .)system call
.
.
.
. .
( .)kernel mode
.
.
()20
( )library routine ( )issues a trap
( ).
.
( )
copy_to_user .
:
open, read, write, close, wait, exec, fork, exit, kill
.
203 FreeBSD 221 .
XP
( Vista )Windows 2000
( :)2-0
()22
.0.6
.
.
.0.6.0
.
.
.
(.)5-0
( :)4-0
()23
0.6.2 ( )multiprogramming
( .)5-0
.
.
.
.
( :)5-0
.0.6.2 ()Time-sharing
.
.
.
.0.6.4
()
( ) .
()24
( )idle
.
34 7 .
( )
.
( )
.
.
.
.0.7
... . :
( :)windows
.
XP ( )
advanced server 3111
(.)servers
( :)UNIX 0374 Dennis Ritchie Ken
Thompson .AT & T Bell
()25
. .0391
:
V Unix o
BSD o
( high level
)language .C
( :)Mac
.
( :)Linux
.
( ).
.0.8
( )hardwrae .
.
()26
.0.8.0
Mainframe Systems
( )dump terminal
.
( )
.
.0.8.2
.
.
.
XP
.FreeBSD (Single user Multi-
)task
( Disk Operating
) .)System (DOS
(.))Single user Single task
()27
.0.8.3 ( )Multiprocessor
(.)multiprocessor
:
(
).
(
).
.
: .
()multi-core
( )dual core ( )quad core
.
.
.
:
.0.9.2.0 )Symmetric multiprocessing (SMP
.
.0.9.2.3 Asymmetric multiprocessor
()28
.0.8.4
.
.
:
.
.
(.)load balancing
:
.
()29
( :)6-0 .
.0.8.6 ()Real-time
:
.
.
.
.
.
( )Robotics (.)7-0
.
()31
( :)7-0 .
()30
Palm, Windows Mobile, Symbian
( :)9-0 .
()32
.
.
.
( :)3-0
.0.8.01
Server Systems
.
Windows Advanced Server
.Unbuntu Server
.
( )web server .
. .
.0.9
.
()33
.
.
()34
.0.01
( )
5 :
)0( .
.
:
()0
()0
.
:
)0( DOS
XP
:
()35
()0
:
()0
:
.
.
()0
( )hand held :
)0( .
.
.
)0( .
:
()36
)0( Palm
Unix
)0( Symbian
Zenex
()0
ROM )0( .
( )
.
( )cluster
.
.
( )multiprocessor
.
.
( .)Round Robin
.
( )multi-core
.
DOS ( Single user
.)Multi-task single user single task
()37
(.)Single user Multi-task
.
.
DOS ( Single user
F .)Multi-task
(F .)servers
F
T
T
T .
()38
.0.00
.0
.3
()
.2
.4
.5
.6
.7
.9
.3
.01
.00
.03
( )real-time
.02
.04
.05
.06
.07
.09
()39
.03
.31
.30
XP
.33
XP
C++
.32
( Windows API)
.34
( )live CD
XP
.35
cmd ( )run
( )command line interpreter DOS
cls, dir, time, date, ver
()41
.36
( )
( .)terminal
.37
()40
()42
()43
.
.
.2.0 ()computing
( )0-3:
.
.
( ).
/ () (
).
( :)0-3 (.)computing
()44
.
.
. ()
.
.
.
(
( ))3-3:
.0 (.)Input devices
.3 ( (.))Processor & main memory
.2 (.)Output devices
.4 (.)Secondary storage
( :)3-3 .
/
( ).
()45
:
: .
: .
: .
: .
: .
:
.
.
.
( :)2-3 .4
()46
.2.2
(.)2-3
( :)4-3 .2
.3.3.0 ()controller
( )controller :
.
.
( )buffer
.
.
()47
(.)concurrently
.
.
.
.2.3 ()Interrupts
( /)
.
( .)interrupt service routine
(
) .
. :
/.
( )timer
( )hardware failure .
( P1)
( P2) .
.
( )P2 ( )interrupt handler
()48
.
(.)P1
.2.4
dual mode
.
.
( )bit
( )kernel mode
( .)user mode
.
(
)system call
(.)-3
( :)-3 ( ) 3
.2.5
timer
.
( )infinite loop
()49
.
( )timer .
.3.5.0 :
.
( ).
.
.
.
.
( fatal
)error ( ).
.3.5.3
7 )61*7( 431
( )
.
.2.6
:
.registers
() .cache
()51
() .main memory
.magnetic disk
.optical disks
.magnetic tape
:
.0
.3
.2
.4
.3.6.0 ()volatility
:
: (
)volatile
: ( non-
.)volatile
.3.6.3
( )
(
) .
.
:
()50
() 01 (.)ns
() 011 (.)ns
05 (.)ms
.3.6.2
.
.
(:)MB
() 311 .
01 .
1.110 .
(.)01-3
()52
( :)01-3 .
.3.6.4 ( )cache
. .
L1
.L2
.
.3.6.4.0
( )
()
.
( .)03-3
.
.
.
( :)03-3 %61 %7 .
()53
()
(.)02-3
:
.
.
( )
.
(.)04-3
( :)04-3 .
()54
.2.7
.
( )
( ).
( :)5-3 .
.
( )
()55
( .)5-3
.
(.)3.3.0
.
.
.2.7.0
( )
( )0-3
( )ASCII
( )
.
:
:EBCDIC
( : )ASCII .
.Unicode
unicode
.
()56
( :)0-3 .
.2.7.3
( )
ON OFF
ON 0 OFF
( )6-3
( 9) .
(.)6-3
( :)6-3 9 .
()57
( )A
( 10111110 ( ))0-3 (-3
.)9
( :)7-3 .
ON OFF 1 .0
. .
( :)9-3 A .
()58
:
.
.2.8
.
.2.8.0 ( )Booting
:
( .)ROM
.
().)Power On Self Test (POST
bootstrap loader
( )ROM
.
.
bootstrap loader
.
.2.8.3
.
(.)2-0
()59
:
( ) :
....
:
.
:
( )ready
.
.2.8.2
() (
) :
( :)fetch
( ).
( :)decode
()
.
( :)fetch operands
(
3) .
()61
( :)execute
.
: .
(.)00-3
( :)00-3 .
.2.9
.
.
()60
.2.01
.0
( )sequential access
(.)random access
.3
Bootstrap loader (.)ROM
.2
( )POST (.)ROM
.4
( )CU ( )ALU (.)registers
.5
( )
3 .
0111 . 339
0111.
()62
.2.00
.0
.3 ( ).
.2 L1 L2
.4 cache miss cache hit
.5 ( )controller
.6 ( )user mode ( kernel
)mode
.7
.9 ( 4)
.3
.01
.00
.03 ( )
.02
.04
.05 () ( )0391
()63
()64
()65
()66
()Porcesses
( )process management
:
(.)porcesses
(.)Threads
(.)CPU scheduling
(.)Process synchronization
(.)Deadlocks
()
.
.3.0
... .
.
()67
. .
. .
()68
.6 ( )
.7 .
.9 .
.3 6 .
()69
( :)0-2 .
.3 .4
( Process
).)Identification Number (PID
:
:
( )background .
:
() ()parent
( )child
( .)3-2
.
:
.
( :)batch
.
()71
( :)3-2 .
2.4.0 ()()fork
)( fork
( )agrements
( .)process ID )( fork
.
)( .fork
)(:fork
)( fork
.
)( fork
.
()70
)( fork
(.)process ID
pid_t .sys/types.h
)( getpid
. )( fork
)( fork )( getpid
printf
.pid
()( )fork(); pid=getpid )(.pid=fork
>#include <stdio.h
>#include <sys/types.h
{ )void main(void
;pid_t pid
;)(fork
;)(pid = getpid
;)printf("This line is from pid %d, value = %d\n", pid, i
}
( )exec
exit .
.3.5
exit .
()72
wait
.
) (abort:
.
( ).
.exiting
.
.cascading termination
:
( ).
.
.
.C :
fork() .
exec() .
exit() .
wait() .
Kill() .
()73
C .
(
) .
.3.6
.
( ( .))single processor system
( )
.
( )ready ( )
( ( ))running
(
( .)terminated
(
( .))blocked .
( ( )
( )) .
() ().
( )
.
( ).
()74
.3.7
()75
..
( :)4-2 ( .)PCB
( :)5-2 ( P0 .)P1
()76
.3.9
.
.
.
.
Ctrl+Alt+Del
Processes
(.)6-2
( :)6-2 .
()77
(.)Mem Usage
( )WINWORD.EXE awq
.48,808k
.End Process
.Administrator
()
.
( )idle .
.
.NET
.NET
.
.
visual basic.net
process .NET
( ) . :
Imports System
Imports System.Diagnostics
Module Module1
)(Sub Main
Dim thisProcess As Process
thisProcess = Process.GetCurrentProcess
Dim pname As String = thisProcess.ProcessName
Dim started As DateTime = thisProcess.StartTime
Dim pID As Integer = thisProcess.Id
Dim mem As Integer = thisProcess.VirtualMemorySize64
Dim phymem As Integer = thisProcess.WorkingSet64
()78
Dim primem As Integer = thisProcess.PrivateMemorySize64
Dim priority As Integer = thisProcess.BasePriority
Dim priClass As ProcessPriorityClass =
thisProcess.PriorityClass
Dim cpuTime As TimeSpan =
thisProcess.TotalProcessorTime
Console.WriteLine("Process : {0}, ID: {1}", pname,pID)
Console.WriteLine("
started: {0}", started.ToString)
Console.WriteLine(" CPU time: {0}", cpuTime.ToString)
Console.WriteLine(" priority class: {0}, priorty:
{1}", priClass, priority)
Console.WriteLine(" virtual memory: {0}", mem)
Console.WriteLine(" private memory: {0}", primem)
Console.WriteLine(" physical memory: {0}", phymem)
Console.WriteLine(" try to change priority ..")
thisProcess.PriorityClass = ProcessPriorityClass.High
priClass = thisProcess.PriorityClass
Console.WriteLine(" new priority class: {0}",
priClass)
Console.Read()
End Sub
End Module
( )
. ID
.) priority(
:
Dim allProc() as Process
allProc = Process.GetProcesses()
:
)79(
Foreach thisProc as Process in allProc
Next
.9.01
( ) )process identification number (PID .ps
ps ( )Ubuntu
(.)7-2
( :)7-2 ( ) .ps us :
.2.4.0 ().
. PID ""
( )task " " ( )task manager .
()81
3.00
( independent or
. )cooperating
.
interprocess
) communication(IPC
( )9-2:
Shared memory
Message passing
( :)9-2 .
()80
.3.02
:
.0 :
.
.
.
()0
.3 :
PCB
PCB .
) (abort
.
( )exec system call
.fork()
.
.
.2 :
()82
. 0 .3
.2 .4 //
. .5// .6
()83
.3.03
.0 ( )process
.3 ( )process states
.2 ) (PCB
.4
.5
.6 ( )
( )PCB PCB .
) (abort
.
( )exec system call
.
.7
.9 ( )
()84
()85
()86
()87
()CPU Scheduling
( )multiprogramming
( ) .
( )scheduler ()
(.)scheduling algorithm
(
.)CPU utilization
()88
( .)I/O bound
CPU
bound
.I/O bound
.4.2
.
:
long-term scheduler (or job
) scheduler
.
.medium-term scheduler
short-term scheduler (or CPU
) scheduler
.
(.)0-4
( :)0-4
()89
( :)3-4
()91
( .)3-4
.
/
.
:
.0
.3
.2
.4 Terminates
0 4
. .non-preemptive
43
. .preemptive
( : )non-preemptive scheduling
:
()90
.4.3.2.0 Dispatcher
:
o :switching context
.
o .user mode
o .
.
:Dispatch latency
( ).
()92
( :)CPU utilization
.
( :)Throughput
.
( ) ( :)Turnaround time
( () ).
( :)Waiting time
( )ready queue
( )ready queue .
( :)Response time
( )new () .
.4.4
:
: .
: .
: .
: .
( :)response time
.
()93
24
P1
P2
P3
()94
P1 P2 P3
(: )Gantt Chart
.0 = (07 = 2/)37+34+1 .
.3 = ( 37 = 2/)21+37+34 .
.2
:
= ( 2 = 2/)6+2+1 .
= ( 02 = 2/)21+6+2 .
.
.4.5.2
)Shortest-Job-First (SJF
.
.
()95
.
.
(
).
.
.
:
( :)Non-preemptive
.
( :)Preemptive
.
()3
(
).
P1
()96
P2
P3
P4
( )Gantt chart
:
= ( 7 = 4/)06+3+2+1 .
= ( 02 = 4/)34+06+3+2 .
()2
.
P1
P2
P3
P4
()97
(.)preemptive
= :
01 = 1 - )01 + 1( = P1
1 = 0 0 = P2
05 = 3 -07 = P3
3 = 2 -5 = P4
= ( 6.75 = 4/)3+05+1+01 .
= ( 04.5 =4/)01 +36 +5 +07 .
()4
.
()98
P1
P2
P3
P4
1 = 1 - 1 = P1
6 = 3 - 9 = P2
2 = 4 - 7 = P3
7 = 5 - 03 = P4
= ( 4 = 4/)7+2+6+1 .
= ( 01.75 =4/)06+03+9+7 .
()5
( )4 .
()99
P1
P2
P3
P4
( )Gantt chart :
3 = 1 ))3-00(+1( = P1
0 = 3 ))4-5(+3( = P2
1 = 4 4 = P3
3 = 5 7 = P4
= ( 2 = 4/)3+1+0+3 .
= ( 3.75 =4/)00+5+7+06 .
.4.5.3 ()Priority
( ) .
5
7 5 7 .
:
()011
(.)Preemptive
(.)non-preemptive
.4.5.2.0 ()Starvation
(( )Starvation
.
.
( )Aging
.
()6
( ).
10
P1
P2
P3
P4
P5
()010
= ( 9.3 = 5/)0+09+06+1+6 .
= ( 03 = 5/)6+03+09+0+06 .
( :)7
( " ").
10
P1
P2
P3
P4
P5
()012
( )quantum or time slice 01 011
.
Quantum
Quantum 01
01 ( )
01 .
.
2 01
2 01 .
.
()9
( )Quantum 4
.
24
P1
P2
P3
()013
6 = )4-01( + 1 = P1
4 = P2
7 = P3
= ( 5.67 = 2/07 = 2/)7+4+6 .
= ( 05.67 = 2/47 = 2/)01+7+21 .
()3
31 .
P1
53
P2
17
P3
68
P4
24
()014
90 = )37-030(+)31-77(+1 = P1
31 = P2
34 = )007-024(+)57-37(+27 = P3
37 = )77-007(+57 = P4
= ( 72 = 4/)37+34+31+90 .
.4.6
C# VB.NET
C,C++,JAVA
()
.
( )console application
basic.NET :
()015
visual
Dim x, y As Integer
Console.Write("Enter number of processes: ")
x = Console.ReadLine()
Dim z(x - 1) As Integer
For y = 0 To x - 1
Console.WriteLine(" Enter burst time for process " & y)
z(y) = Console.ReadLine()
Next
) (
:) FCFS(
wt(0) = 0
For i = 1 To x - 1
wt(i) = z(i - 1) + wt(i - 1)
Next
wt(0)=0
w(1) = z(0) + wt(0)
.
)wt(
:)awt(
Module Module1
Sub Main()
Dim x, y As Integer
Console.Write("Enter number of processes: ")
x = Console.ReadLine()
Dim z(x - 1), z2(x - 1), wt(x - 1) As Integer
For y = 0 To x - 1
Console.WriteLine(" Enter burst time for process " & y)
z(y) = Console.ReadLine()
Next
Dim twt As Double = 0.0
For i = 0 To x - 1
z2(i) = z(i)
Console.WriteLine("Burst time for p" & i & " = " & z2(i))
Next
wt(0) = 0
For i = 1 To x - 1
wt(i) = z(i - 1) + wt(i - 1)
Next
For i = 0 To x 1
Console.WriteLine("waiting time for p" & i & " = " & wt(i))
twt = twt + wt(i)
)016(
Next
Dim Awt As Double = Twt / x
Console.WriteLine("Total
Weighting Time=" & twt)
Console.WriteLine("Average Weighting Time= " & Awt)
Console.Read()
End Module
)017(
.4.7
.0
.3 :
P1
P2
P3
P4
=( 6 = 4/)6+5+02+1 :
( )Gantt chart .
= .6
.2 ( )starvation
.4 :
P1
P2
()018
P3
P4
10
P5
:
()Gantt chart
:
o ( )FCFS
o ( )FCFS
o ( )SJF ( )
o ( )SJF ( )
o ( )SJF ( )
o ()
o ()
o ( )RR Q=2
o ( )RR Q=2
o
()019
.5 C ( )4
FCFS, SJF, :
.RR, Priority
.6 :
P1
10
P2
P3
P4
P5
:
.0
.3
.2
.4
.5
( )SJF (
).
( )SJF ( ) .
( )SJF ( ).
( )RR ( Q=1 ).
()
.
.7
:
P1
()001
P2
P3
P4
P5
( )Gantt chart
( )RR :
o Q=1
o Q=2
o Q=3
.
( )turn around time .
: () .
.9 31 .
P1
53
P2
17
P3
68
P4
24
()000
()002
()003
()004
()005
Thread of Execution
.5.0
.
:
5+6+7+8
:
6+5 .13
7 13 .20
8 20 .28
.5.0.0 ()
() .
3 ( 5+6=13
.)20+8=28 13+7=20
( ).
.5.0.3 ()
5+6 7+8 (
)
()006
( 33%
) .
.
:
.
.
.5.2
( .)single thread
( )multiple threads
( .)0-5
( .)concurrency
( )PCB
.
:
o (.)stack
o ( .)register
o .
o .
( .)lightweight process
.
()007
. .
.5.2.0
() () .
( )
()
. .
( )PCB
( )
.
.5.3
.
()008
.
. .
( :)0-5 : .
: .
.5.3.3
.
.
.
.win32 windows.h
)(.CreateThread
.
()009
.5.4
.
.5.4.0
( )Thread . :
class th extends Thread
Thread th
. th run
.Thread :
{)(public void run
}System.out.print("Inside thread"):
}
th:
) (th t1 = new th
t1 :
) (t1.start
: t1
.
. .main
( )0-5 .main
class th extends Thread{//
()021
{)(public void run
}System.out.print("Inside thread"):
}
{)] [public static void main(String args
th t1 = new th( ); //
t1.start( ); //
};)"System.out.print("Inside main
}
()0-5
.5.4.3
() :
)(Suspend
)(Resume
)(Sleep
()
.
)(Resume
)(.suspend
)(Stop
()
.
( )0-5 .
()020
.5.5
( )3-5:
( :)new .new ( )0-5 th
:
;)(th t1 = new th
() :Runnable )( start
)( run ( t1 ( ))3-5
t1 .Runnable
( )blocked ( :)not Runnable
)( suspend )(.sleep
( :)Dead )( run
)(.stop
( :)3-5 .
)( isAlive ( () ()).
()022
.5.6
Context Switch
( )PCB
.
( )PCB ( ( ))2-5
. :
(.)PC
(.)stack
.
(
)
. ( context
)switching
( )PCB ( ) ( )PCB
( ).
.
(.)context switching time
.
( )
()023
( )
.
( ).
( :)2-5 .
.5.7
. .
.5.7.0
( )4-5 ( )
.
( ).
.
()024
( :)4-5 .
.5.7.3
( )web server
.
.
()
.
()025
( :)5-5 .
.5.8
Pthreads
Pthreads
( )
Pthreads . C
.
.5.8.0
)( pthread_create
:
(.)thread identifier
null .
.
()026
( )argument
null
.
:
;)pthread_create(&th_ID, NULL, th_fun, &value
th_ID
th_fun
.value
)( pthread_create
.
)( pthread_join
.main
.5.8.3
pthread1.c
( )3-5
.
:
C compiler: cc -lpthread pthread1.c
()027
Thread 1
Thread 2
Thread 1 returns: 0
Thread 2 returns: 0
)2-5(
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *p_message( void *ptr );
main(){
pthread_t thread1, thread2;
char *m1 = "Thread 1";
char *m2 = "Thread 2";
int r1, r2;
/* * /
/* * /
r1 = pthread_create( &thread1, NULL, p_message, (void*) m1);
/* * /
r2 = pthread_create( &thread2, NULL, p_message, (void*) m2);
/* * /
pthread_join( thread1, NULL);
pthread_join( thread2, NULL);
printf("Thread 1 returns: %d\n",r1);
printf("Thread 2 returns: %d\n",r2);
exit(0);
}
)028(
*/ */
) void *print_message_function( void *ptr
;{ char *message
;message = (char *) ptr
;)printf("%s \n", message
}
5.8.2
)( pthread_cancel
.
)( pthread_cancel
(.)memory leak
()029
.5.9
pthread :
()0
( )Fibonacci series:
1,2,3,5,8,13,
:
.
Enter number of Fibonacci numbers to generate ? 5
1,2,3,5,8
()3
1 .
.
Enter number to generate primes less than or equal to ? 5
2,3,5
()031
.5.01
.0
.3
.2
.4
.5
" "
( )
.6
.7
.9
pthreads
.3
.01
.00
.03
()030
()032
()033
()synchronization
.6.0
.
.6.2
Concurrency
.
( )independent processes
( .)cooperative processes
( )WinWord
( )media player
.
( )concurrent processes
(.)concurrent threads
. /
.
()034
.6.3
.
( ) (.)synchronization
( shared
)variables ( .)message passing
.
:
:
.
.
:
.
.
( )pipeline
. ( ):
$ ls | wc
()035
ls wc
()
( (
)).
( ( ))buffer
/ .
( )producer (.)consumer
( )
/ .
:
.
.
.6.3.3
( )
( ( )context switching
).
().
( )
( ) .
.
()036
.6.4 ()competition
.
.
( .)race condition
.
()
.
(.)process competition
.6.4.2
.
.6.4.3.0 ( )file server
.
( )
. .
( .)overwrite .
.
( .)race condition
.
()037
.6.4.3.3
.
" "
( )
( ) .
.
6.4.3.2
.
( 0511)
( 011
) 0411 .
( 0511)
( 311
( 0211) .
.
( )
()038
( .)race condition
.
.6.4.3.4 ( )race condition ()critical section
:
x :
o .)read x( x
o (.)x=x+1
o ).(writet x
.
.2
x
.
( critical
.)section
.
.
.6.5
.
()039
(.)exclusive access
.6.1.3.3
The first readers-writers problem
()041
.
.
.6.5.0.3
The second readers-writers problem
(
)
.
( )starvation
.
.
.6.5.0.2
The third readers-writers problem
.
()040
.
.
.6.5.3 ( )producer-consumer
(bounded-
.)buffer
.
.
( :)0-6 .
.6.5.3.0
( .)sleep
. ( )sleep
. ( )semaphore
(.)inter-process communication
.6.5.3.0.0
()042
( )0-6 count
item . :
:
)if (count == BUFFER_SIZE
( )sleep
:
)putItemIntoBuffer(item
count :
count = count + 1
:
)if (count == 0
( ) .
:
)(item = removeItemFromBuffer
count:
count = count 1
()0-6
int count
{ )(procedure producer
()043
while (true) {
item = produceItem()
if (count == BUFFER_SIZE) {
sleep()
}
putItemIntoBuffer(item)
count = count + 1
if (count == 1) {
wakeup(consumer)
}
}
}
procedure consumer() {
while (true) {
if (count == 0) {
sleep()
}
item = removeItemFromBuffer()
count = count - 1
if (count == BUFFER_SIZE - 1) {
)044(
)wakeup(producer
}
)consumeItem(item
}
}
.
:
count () )if (count == 0
(.)sleep
(
.)sleep
( count .)0
().
( )
( )sleep ()wakeup
( .)count=1
(
).
:
)if (count == BUFFER_SIZE
()045
.
( )
.
.6.5.3.0.3 ()semaphore
.
( )
( )
.
( )
.
.
.
( )
(
) .
().
()046
( )3-6 fillCount emptyCount
.
( emptyCount
) .fillCount
fillCount
.emptyCount
()3-6
Semaphore fillCount=0
semaphore emptyCount = BUFFER_SIZE
{ )(procedure producer
{ )while (true
)(item = produceItem
)down(emptyCount
)putItemIntoBuffer(item
)up(fillCount
}
}
{ )(procedure consumer
{ )while (true
)down(fillCount
()047
)(item = removeItemFromBuffer
)up(emptyCount
)consumeItem(item
}
.
/ ( race
.)condition
()048
( :)3-6 .
5
. .
.
.
( .)3-6
0 3
3 2 (
) (.)deadlock
:
()049
.
. ( )
(.)starvation
.
.
:
( )semaphore
()
() .
.
:
:
.
.
( ).
.
()051
()050
.mutexes
A .
.T
.
.
. :
{while true
)wait(T
choose smokers i and j nondeterministically
making the third smoker k
)]signal(A[k
}
i:
{ while true
)]wait(A[i
make a cigarette
)signal(T
()052
smoke the cigarette
}
.6.5.5
Rendezvous
. :
.
.
.
.
( ).
()053
( () )
( :)mutual exclusion
.
( )mutex
.
(
).
(.)critical section
mutex
( ) .
.
. ( single
.)sleeping barber problem ()pseudo-code
.
P V .
Semaphore Customers = 0
Semaphore Barber = 0
Semaphore accessSeats (mutex) = 1
int NumberOfFreeSeats = N //
:
while(true) { //
P(Customers) //
P(accessSeats) //
NumberOfFreeSeats++ //
V(Barber) //
V(accessSeats) //
//
()054
:
while(true) { //
P(accessSeats) //
if ( NumberOfFreeSeats > 0 ) { //
NumberOfFreeSeats-- //
V(Customers) //
V(accessSeats) //
P(Barber) //
//
} else { //
V(accessSeats) //
//
}
}
()055
.6.6
.0
.3
.2
.4
.5
( )race condition
.6
( )crtitical section
.7
Rendezvous
.9
.3
()056
()057
()058
()deadlock
(
)
.
.
.7.0 ()resource
(
) ( ).
.7.3
( ) (
)1 3
3 ( 1
)
.
.2.3.0
() ()
( )
(.)0-7
()059
( :)0-7 .
( )3-7
.
( :)3-7 .
.2.3.3
( ).
.
.7.2
:
()061
( :)preemptable resources
.
( :)non-preemptable resources
()
(.)CD writer
.
.7.4
:
.1 ( :)mutual exclusion
.
.3 ( :)hold and wait
.
.2 ( : )non preemption
.
.4 ( :)circular wait
.
()060
.7.5
.
:
( )2-7 R S.
( )2-7 A B.
() ()
( ) ( )b( )2-7 B
.S
() ()
( )a( )2-7 R
.A
( :)2-7 .
.2.5.0
( )2-2 D
U R R E
V G G U
D .
()062
( :)4-7 .
( )4-7 ( )R
R .
.7.6
()
( )
.
:
.
( ) .
.
.2.6.0 ( ())The Ostrich Algorithm
(
).
()063
:
.
.
.7.6.3
.
.7.6.3.0
(
.. ).
7 A G
:
A R S .
B T .
C S .
D U S T .
E T V .
F W S .
G V U .
( )
()064
(.)5-7
( :)5-7 .
( )5-7 U
U
.
.7.6.3.3
( 5 4
...)
( )matrix .
n m E1
( ) E2 (
) .Em ( )vector .
7 6 5
:
(7
()065
)5
( )6-7
5 4 2
:
(5
)3
( )7-7
( )
:
(7
= )5 .
(5
= )3 .
(2
= )2
( )9-7
( )
.
:
()066
( )3-7
( )3-7 :
5 .
.
.
.
( )
:
()01-7
( )01-7 :
.
()067
5 6 7.
4 2 2.
4 4 4.
( )6-7 ( )9-7
( )3-7
( )01-7
( )9-7
()
. ( )01-7
( )9-7
.
:
(2
= )2
(2
= )2
(0
= )0 .
()00-7
()068
.
(
)
:
(0
= )0
(5
= )1 ( )
(2
=)2 ( )
(7
= )3
( )03-7
( .)01-7
(.)02-7
(7
= )3
(4
= )3
(3
= )0 .
( )02-7
( )
( ):
(3
= )0
(0
= )0 ( )
()069
(4
=)3 ( )
(7
= )3
( )04-7
( )04-7
( .)01-7
. .
()2
.
:
=(4
)1
()071
(
) :
(4
)1
(2
)1
(2
)0
( )
:
=
(2
)0
( )2
(2
)0
(0
)0
2 :
2
(0 0 0
)0
(2 1 0
)0
(0 1 2
)0
(2 2 2
)0
1
0
()070
0
0
( )
:
=
(2
)0
( )3
(1
)0
(1
)0
3 :
3
(1
)0
(2
)1
(1
)0
(4
)1
3 .
.2.6.2
:
:
(
()072
( )CD writer
.
.
(
) .
: (
( ))kill .
.
.2.6.4
:
()
()073
( )04-7
( )
.
2 :
( :)05-7 .
2 3
4
7 . .
( ).
( .)06-7
()074
0 :
( )06-7
( 4)
5 (.)07-7
5 :
( )07-7
5
( .)09-7
1 :
( )09-7
( 7)
7 (.)09-7
()075
7 :
( )09-7
6 ( .)03-7
0 :
( )03-7
( 3)
01 (.)31-7
01 :
( )31-7
( ).
()076
( )unsafe .
(.)30-7
2 :
3 :
1 :
4 :
( )30-7
()077
( 4)
.
.7.6.4.3
.
( )
.
.7.6.4.3.0
.
()
( ) . ( )33-7
.
()078
( :)33-7 .
.7.6.4.3.3
.
.
.
.7.6.4.3.2 ( )
:
.
( )CD writer
CD .
.7.6.4.3.4
2 2
.2
( )32-7 3
.
( )4
4 .
.
()079
2
4
( :)32-7 .
Pmax
Pcurr
A=(3,1,1) :
Pmax Pcurr
:
Dim Pmax(2, 2), Pcurr(2, 2), avl(2) As Integer
Pmax(0, 0) = 3
Pmax(0, 1) = 3
Pmax(0, 2) = 2
Pmax(1, 0) = 1
Pmax(1, 1) = 2
Pmax(1, 2) = 3
Pmax(2, 0) = 1
()081
Pmax(2, 1) = 1
Pmax(2, 2) = 5
Pcurr(0, 0) = 1
Pcurr(0, 1) = 2
Pcurr(0, 2) = 2
Pcurr(1, 0) = 1
Pcurr(1, 1) = 0
Pcurr(1, 2) = 3
Pcurr(2, 0) = 1
Pcurr(2, 1) = 1
Pcurr(2, 2) = 1
:
avl(0) = 3
avl(1) = 1
avl(2) = 1
: j
For i = 0 To 2
Console.Write(Pmax(j, i) - Pcurr(j, i) & "
Next
")
: j ) avl(
For i = 0 To 2
If ((Pmax(j, i) - Pcurr(j, i)) <= avl(i)) Then
Console.Write(avl(i) - (Pmax(j, i) - Pcurr(j, i)))
Else
Console.Write("not enough")
' stop
End If
Next
)080(
.7.8
.0
.3
.2 ( )
( )
.4
.0
.3
.2
.4
.5 ( )safe
.6
.0
.3
.2
.4
.7
.0
.3
()082
.2
.4
.9
:
.3
E C
R .
() A ()2 1 0 0
()
()083
A C A
A ( )
A A (1 1
)1 1
( )C
( )R A ()2 2 2 0
C R:
new A R
(.)4 2 2 1
C R:
() A ()
( ).
.01
()084
( )R :
()1 0 1 1
C R:
(.)3 0 1 2
C R:
()085
( )3 0 1 2 .
.00
.0
.3 ( )Kill
.03
A,B,C Has
Max (
).
( )
()086
()
( )
()087
.7.9
.0
()
(
) :
D A B C D
2 2 6 2 1
0
6
2
6
C
1
5
5
5
5
B
2
7
3
6
6
A
2
1
2
0
0
D
2
0
3
2
3
C
1
0
4
4
3
B
0
2
3
6
2
A
1
1
1
0
0
P0
P1
P2
P3
P4
P0 0 A 3
0 .A 3 D 3
.D
:
( )
( )safe state
P0 0 1 1 0
P1 0 3 3 0
.3
( ) ( )
( )
()088
()089
()091
()090
Main Memory Management
( )ram
2MB Ram
2 2097152 = 2* 1024 * 1024
.
. .
( ()one CPU clock
) ( ) .
() .
.
.
. ( ).
( ) .
.
:
.
.
()092
.
.
() .
(.)swap
.
.8.0
()
. .
1 ( )MB :
0149576 = 0134 * 0134 * 0
(.)1-8
0
1
2
3
...
1048576
()093
( :)0-9 .
.8.3
:
.
.
: .
: .
: .
:
.
.9.3.0
.
.9.3.3
( .)1-8
.
()094
( :)0-9 .
0391
( )3-8
.
( :)3-8 .
( )
(
) .
.
.
()095
( L1 )L2
( .)3-8
( .)consistent
.
.8.3
:
.
( )non volatile .
. .
()
( ) .
( )
( )
.
. .
( ) .
.8.4
:
()096
.
.
.
2 ( ).
4
.
2
7
:
.
(
).
.
( 2)
.
()097
( :)2-9 .
4
(
).
2
.
( ) .
.
( )rom
.
()098
.8.5
( )2-9
()
.
.
( ) .
(
)
.
:
( ).
( ).
(.)fixed partitions
.
.
.
.
()099
.8.6
()single program
( )single task ( single
)program (.)2-8
( :)4-9 .
.8.6.0
:
:
o
(.)1-8
o
( ).
o .
()211
:
.
( :)5-9 .
.8.6.3
(
.)not enough memory
( )Protection register
.
()210
.
.DOS
.8.7
( )multitasking
( .)multiprogramming .
( )media player .
.
( )DOS
( .).
:
.
( )single processor
.
( )dual core ()multiprocessor
.
.9.7.0
.
.9.7.0.0 ( )
()212
( )2.9
( ) :
.
.
( ).
.
().
.
.
() .
(
) . () ()
.
.9.7.0.3
()213
.
.9.7.0.2 ( )
.
.
.
( )multi-core (.)multiprocessor
.8.8
.
.
()214
( :)6-9 (.)0 -9
.9.9.0
.
1
2
3
4
10
20
50
200
244
( :)0-9 .
( )0-9 ( .)6-9 :
( 4 4 ).
2 ( ).
311 ( .)4
()215
( )0-9 (.)7-9
( :)7-9 (.)0 -9
.9.9.3
:
( :)best-fit
() .
( :)first-fit
.
( :)worst-fit
()216
(
).
()0-9
P3=200 P2=50 P1=10
( )0-9
( :)best-fit P1 0 P2 4
P3 ( ) (.)9-9
( :)first-best P1 0 P2 4
P3 ( ) (.)9-9
( :)worst-fit P1 4 P2
P3 )031=01-311( 4 .
( :)9-9 (.)0-9
( )3-9
()217
.0 .
.3 :
P1=5, p2=100, p3=40, p4=500, p5=200 :
ff
bf
wf
()2-9
():
100k, 500k, 200k, 300k, 600k
()218
( )ff ( )bf
( )wf :
P1=212k, p2=417k, p3=112k, p4=426k
:
( ).
()
(:)ff
(:)bf
(:)wf
.8.9
( )
(.)3-9
()219
( )0( :)3-9 ( )3 51
( )2 311.
.9.3.0 ()fragmentations
External Fragmentation
( )3-9
(.)01-9
:Internal Fragmentation
4 (.)9-9
compaction
.
:
.
.
()201
.
.
.
()4-8
936 .
334 231 399 64
(( )01-9) :
=
64 = )399+334+231( 936.
039
.64 > 039
.
.
( )fragmentation (( )01-9) .
(( )01-9).
()0-9
250k (h )01-9
:
96+96+64=256K
()200
( :)01-9.
()3-9
250k ()00-9
.
()202
( :)00-9 .
.8.01
( )
.
.9.01.0 Relocation
( )swap
.
()203
.
530
611 611
(.)03-9
0
521
...
75
600
( :)03-9 .
630 (-9
.)02 611 611
.
0
...
75
...
600
621
...
700
...
( :)02-9
()204
711 711
011 .011+711
.
.9.01.3 Protection
. ( )malicious program
(
( )jump ) .
.
.9.01.2
( )base (.)limit
(.)12-8
()205
( :)04-9 .
( 3 )
( )
.
( )Load 345 :
245 ()limit ()
( trap: address
.)error
:
)Load (123+16000
(.)05-9
.
( :)05-9 .
()206
...
75
...
111
110
113
112
114
...
076
077
079
073
...
111
611
630
633
632
634
635
...
737
739
733
911
( :)06-9 .
: ( Memory
).)Management Unit (MMU
.9.00.0 ( )MMU
()207
()
( MMU
)246 MMU (
)04246 (-9
.)05
.9.00.3
( )base register MMU
( ) .
( )06-9 630
.073 MMU
.
:
0-
: + 0-
.
( )06-9
630 .
MMU .
()1-8
( )11-8 :
()208
2
122
333
( )11-8 ( )631
( .)122 MMU
:
631 = 631 + 2
228 = 631 + 122
.
()6-8
:
631
228
1333
:
2 = 631 631
122 = 631 228
()209
( 322 = 631 1333 ).
.8.02 ()Paging
:
.
.
()
.
(
) (
)
.
.9.03.0
( )pages (
) ( .)frames
(.)3-3
.
Internal fragmentation .
4kb 110kb
:
()221
110/4 = 27 2 27
2kb (
2kb )2kb
28 2kb .
.9.03.3
:
( ).
( .)offset
( :)07-9 .
p=7 d=20 ( 30
) .
:
.
().
( )hardware
.
.
()220
( :)09-9 .
( )09-9
()
.
(.)03-9
()222
( :)03-9 .
()7-9
( (:))5-3
( ) :
()9-9
()223
.
a
a ( )
(=)
( )4 :
5 x 4 + 0 = 20
31 .a
p 3 3 3 2
( ) p :
2 x 4 + 3 =11
11 p.
()224
( :)31-9 .
()3-9
4
.
()225
( :)30-9 .
( :)33-9 .
.9.03.2
()226
( )bit
. v ( )valid
i ( )in-valid
. (.)32-9
( :)32-9 .
( )32-9 0,1,2,3,4,5
v 5,7
i .
.9.03.4 Shared Pages
()227
.
.
.9.03.4.0 Shared code
.
logical
address space ( )34-9 ed
(.)246
.9.04.4.3 Private code and data
.
logical address space ( )34-9
(.)p1=1, p3=2, p2=7
()228
( :)34-9 .
.8.03 ()segementation
.
( )stack.
(-9
.)35
( :)35-9 .
.9.02.0
: (segment-
.) offsetnumber
()229
( .)limit
( )segemet table
.
(.)36-9
( :)36-9 .
()3-9
( )37-9 5
.
()231
( :)37-9 .
0 .20
20 .1400
( 20 )1000
.
()230
+
1420 =20+1400
()01-9
:
1400
1000
( ).
.
.8.04
.
.
.
.
.
.
()232
.8.05
.1 ( )segment table:
/ ()limit
()base
0
300
600
7000
20
300
1000
6000
900
100
:
0, 500
1, 10
2, 500
3, 2400
4, 99
:
()233
2,500 500 (
.)300
.8.06
.1
()234
.3
.2
.2
.1
.6
.2 / (
)
.2.1 :
.2.3 :
633 233 333 133 133
:
P1=5, p2=100, p3=300, p4=500, p5=200, P6=600
:
P6 ff
()235
P6 bf
P6 wf
.2.2 :
CPU
MPU
MMU
MNU
.2.2 2 100K
90K 110K 300K
.300K
.
.
.
.
.7.5
100 K 3 K
:
22 o
24 o
22 o
24 o
()236
.8 ( )
.
.
.
.2 ( )38-8 .
( :)39-9.
233323
133233 .
:
1111 131 132216
()237
:
233323 233322 233323
.01
.00
v
i
()238
()239
()241
()Virtual Memory
.9.0
() .
.
.
.
:
.
.
( )virtual memory
.
.9.2
. (
)
.
.
()240
( )
(.)swap
.9.3
Swapping
( )
. ( )0-3:
( ) (.)swap out
( ) (.)swap in
( :)0-3.
.9.4
:
o .
o .
o .
:
()242
o .
o .
.9.5
.
. ( )3-3 9
06 . 9
( )X ( ).
( :)3-3.
()243
:
.
o
o
( )
( )
.
.3.5.0 ()page fault
( )
page fault
.
:
.abort
:
o .
o .
o
.
()244
o v .
.page fault
( )swap (
) .
(
) .
(
.)page faults
.3.5.3 Page Replacement
()245
.
:
.0
.3 .
.2 victim
.frame
.4 .
.5 .
.6 .
.7 .
()246
.9.6
Page Replacement Algorithms
:
( )first come first out
)(fifo
( )optimal
LRU
LRU approxmination
.
.
page-fault
page faults
.
:
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
0 3 2.
.3.6.0 ()FIFO
()247
( ) .
.
.
()6-3
:
1,2,3,2,1,5,2,1,6,2,5,6,3,1,3,6,1,2,4,3
( )page fault 2 .
0
( )
( 3 )
( 2
) . 2 .
3 ( 0 (
)) . 5
0
5 .4 3
0 (
)6 3 0 .
14
..
()248
.3.6.3
.
()7-3
:
1,2,3,2,1,5,2,1,6,2,5,6,3,1,3,6,1,2,4,3
( )page fault 3 .
3 2 1
3 . 1 2
. 5
.
( )3 21 :
1 5
2 5.
3 6 5
.5 21
()249
2 1
6 1 .
:
9 .
.3.6.2 ())least recently used (LRU
.
( ).
()9-3
:
1,2,3,2,1,5,2,1,6,2,5,6,3,1,3,6,1,2,4,3
( )page fault 3 .
3 2 1
3 . 1 2
. 5
.
( )3 21 :
1 .
()251
2 .1
3 2
5
.5 21
2 1
6 5
. :
11 .
.3.6.4 ()counting-based
.
.:
.3.6.4.0 ())least frequently used (LFU
( )
.
.
.
.3.6.4.3 ())most frequently use (MFU
()250
( ).
.
.3.6.5 ()Second chance
( )FIFO
.
.
:
( )clear
( )set .
( )clearit
.
.3.6.6 ()Clock
()252
.
.
C
D
.
.3.6.7
( C/C++ )
.:
Choose page replacement algorithm:
1. FIFO
2. Optimal
3. LRU
1
Enter number of pages in logical memory:
4
Enter number of frames in physical memory:
()253
Enter reference string:
0 1 2 1 3 1 3 2 1 3 1
frame 0
frame 1
page 0 at frame 0
page 1 at frame 1
page 2 at frame 0
page 3 at frame 1
page 1 at frame 0
page 2 at frame 1
Solution:
0: PAGE FAULT -- added at
1: PAGE FAULT -- added at
2: PAGE FAULT -- replaces
1: found at frame 1
3: PAGE FAULT -- replaces
1: PAGE FAULT -- replaces
3: found at frame 1
2: PAGE FAULT -- replaces
1: found at frame 0
3: PAGE FAULT -- replaces
1: PAGE FAULT -- replaces
Number of page fault= 8
( 8 ):
0 1 2 3 4 8 9 10 11 12 5 6 7 8 2 3 4 8 9 10 11 0 1 2
5 6 5 6 5 6 13 14 15 0 1 2 3 4 8 9 10 11 12 13 14 15
.9.7 ( )
.
.
.
:XP
My Computer .Properties
()254
Advanced Change
()255
()256
()257
.9.8
.0 (:)page refrence string
( )page faults
:
* FIFO
* LRU
LRU
20
18
15
()258
10
8 .
7 .
7
:FIFO
20 .
18 .
()259
16 .
14 .
10 .
10 .
7 .
()261
.9.9
.3
.2
.4 ( )swapping
.5
.6
.7 :
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5
( )page fault FIFO
:
o .
o .
o .
o .
o .
o .
o .
()260
.9 :
7,0,1,2,0,3,0,4,2,3,0,3,2,1,2,0,1,7,0,1
:
o FIFO
o ( )optimal
o LRU
o ( )
.3 ( )
:
1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
( )
:FIFO
o
o
o
o
o
3
03
04
31
____________
()262
:
SWAP IN o
SWAP OUT o
SWAPPING o
STORING o
:
1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
( ) FIFO:
o
o
o
o
o
3
03
04
31
____________
:
o .
o .
o .
o .
o .
o .v
o page fault
()263
()264
()265
()266
()Devices Manager
.01.0
( ) .
( ) .
.
.
.
.
.
.01.2
.
.
.
( peripheral
)devices
.
()267
( )device
.
:
(.)block
(.)character
.
.
(.)interrupts
.
( )device drivers
.
.
( )device driver ( new
)device
.
.01.3 ()controller
:
()268
.0 ( )controller (.)adapter
.3 .
( :)0-01 .
.
.
( )
.
:
.
(.)On or off
.
()buffer
.
()0-01
()269
( )video ram
.
.01.4
))(DMA
DMA
.
( )controllers DMA
. DMA .
DMA
.
.
.
DMA
. :
DMA (
( )).
( ).
DMA .
DMA ( )interrupt
.
()271
( :)3-01 .DMA
.01.4.0 DMA XP
DMA ( device
)manager IDE ATA/ATAPI controllers
.
channel ( )properties
Advanced settings Transfer Mode
( .)-2-01 DMA
(
) .
()270
( :)2-01 DMA .
.01.5
.01.5.0
.
0
2 .
.
DMA .
.01.5.3
.
.
()272
.
.01.5.2
.
.01.5.4
.
.01.5.5
.
.01.6
Principles of I/O Software
:
( )device independence
.
.
()273
( :)uniform naming
. .
( :)error handling .
( )device driver
.
( Synchronous vs. asynchronous
:)transfers
DMA
. .
( )device driver ()block
( )unblock .
( :)buffering
.
( )shared devices ( :)dedicated
.
( .)tape
.
.01.7
:
o .
o .
()274
o .DMA
.01.7.0 ()Programmed I/O
:
.0
.3 / /
.2 .
.4 / .0
OSMAN :
.
.
.
.
.
.01.7.3 ()Interrupt-Driven I/O
.
()275
.
.01.7.2 )I/O Using DMA ( DMA
.
. DMA DMA
.
( :)4-01 .
.01.9.0
( )driver
. .
.01.9.3 ()device drivers
()276
.
.
.
. .
(.)5-01
( :)5-01 .
.01.9.2
:
o .
o .buffer
o .
o .
o .
()277
.01.9.2.0
.
( )b( :)6-01 .
( )a .
(.)6-01
.01.9.2.3
( ) (
) .
.
. .
.01.9.2.2
()278
().
.
.01.9.2.4 ( )
.
01.9.2.5
.
.
.01.9.4
.
.
.01.9
.
:
(
) .
()279
( )7-01
.
( :)7-01 .
.
.01.3.0
(.)9-01
.01.3.3
()281
5 01 .
( :)9-01 .
5 01 .
5 231 .
.
.01.3.2
()
.
()
.
()280
( :)3-01 .
()282
( :)01-01 .
()0-01
202 :
= 203
= 10
= 10
= 203
()3-01
( )0-01 40000 :
() .
.
.
()283
800000.
.
=
203 x 40000 = 8120000
= = 400000
=
203 x 400000 = 81200000
:
800000 / 40000 = 20
20/10 =10 :
.01.01
.
:
(.)seek time
(.)rotational latency
(.)transfer rate
()284
( )
.
( .)requests pending queue
(
).
. :
(.)First come first served
( .)shortest seek time first
( )elevator .Scan
LOOK
( .)C-Scan
C-LOOK
.
()2-01
( )
:
98, 183, 122, 37, 14, 124, 65, 67
()285
.53
.
FCFS (
) ( ):
53, 98, 183, 122, 37, 14, 124, 65, 67
SSTF
( )
.
:
53, 65, 67, 37, 14, 98, 122, 124, 183
()286
SCAN
( )
(
)
:
53, 37, 14, 0, 65, 67, 98, 122, 124, 183, 199
LOOK
( )
( )
( ) . :
53, 37, 14, 65, 67, 98, 122, 124, 183
C-SCAN
( )
(
)
.
( ) . .
:
()287
53, 65, 67, 98, 122, 124, 183, 14, 37
C-LOOK C-SCAN
( )
( )
( )
( )
. :
53, 65, 67, 98, 122, 124, 183, 14, 37
()288
.01.00
.
. FCFS :
Dim req(10), Current_Track, distance As Integer
req(0) = 86
req(1) = 1470
req(2) = 913
req(3) = 1774
req(4) = 948
req(5) = 1509
req(6) = 1022
req(7) = 1750
req(8) = 130
distance = 0
Current_Track = 143
For i = 0 To 8
))distance = distance + Math.Abs(Current_Track - req(i
)Current_Track = req(i
Next
)Console.WriteLine("Distance using FCFS = " & distance
)(Console.Read
req
Current_Track for
.distance .
()289
.01.02
.0 5000 0 .4999
143 .125
:
86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130
( )143
:
FCFS
SSTF
SCAN
LOOK
C-SCAN
C-LOOK
() :FCFS :
143, 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130
7081
() :SSTF :
143, 130, 86, 913, 948, 1022, 1470, 1509, 1750, 1774
1745
() SCAN :
143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 130, 86
9769
()291
() LOOK :
143, 913, 948, 1022, 1470, 1509, 1750, 1774, 130, 86
3319
() :C-SCAN :
143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 0, 86, 130
9813
() :C-LOOK :
143, 913, 948, 1022, 1470, 1509, 1750, 1774, 86, 130
3363
.3 DMA
.
.2 :
* 23, 89, 132, 42, 187 :
* 200 : 0 199
* : 100
:
FCFS
SSTF
SCAN
LOOK
C-SCAN
C-LOOK
()290
() :FCFS 276 :
() :SSTF 273 :
() : SCAN 101 :
() LOOK 241 :
()292
() :C-SCAN 366 :
() :C-LOOK 296 :
()293
.01.03
.0
.3
__________
.2 DMA
.4
.5
()294
()295
()296
(Manager
)Files
()short-term storage
( .)long-term storage
(
) ( .)file
( ).
( )
.
( ) .
.
.00.0
:
.
.
()297
.
.
.
.
.00.3
( )
( ).
( )
.
.
()298
(. )protection
.
(.)creator
(.)owner
( time , data , and user
)identification ( ).
.00.4
:
(.)create a file
.
.
.
(.)append
(.)seek
.
( ).
(.)get attributes
(.)set attributes
.
()299
.00.5
()executable
Obj , o
object
()source
(
)dir, cls
Bat , sh
()Batch
Txt , doc
Text
.00.6
()Archive
access method
(.)sequential access
( .)direct access
.00.7
Directory structures
( )partitions ()minidisks
( )volumes ( )partitions .
()311
.
.
.00.7.0 Single level directory
()
(.)-7
( :)0-00 .
.11.7.3 Two level directory
(
.
()310
( :)3-00 .
.11.7.2 Tree structured directory
.
.
()312
( :)2-00 .
.00.9
. :
( )damage (.)reliability
( ( ))improper access
.
.00.9.0
.
.
.
()313
Backup accessories System tools (.)4-00
.
(.)restores
( :)4-00 .XP
.
.7.9.3
.
... .
( )access permissions
.
()314
:
.Owner
.Group
.Universe
.
.7.9.3.0 XP
XP
Security ( )group or user name
( )permissions
Administrator
( )permissions for Administrators
( )full control ( )Reaa & Execute
(.)5-00
()315
( :)5-00 .XP
.7.9.3.3
.
. ( r )4 (w
)3 ( E .)0 :
ls output
-rwx------
()owner
----rwx---
()group
-------rwx
()other
hosts :
()316
ls -l /etc/hosts
:
-rw-r--r-- 1 root root 288 2005-11-13 19:24 /etc/hosts
:
-rw-r--r- :)owner = Read & Write (rw-
)group = Read (r--
)other = Read (r--
.
chmod
:
Usage: chmod {options} filename
Options (.)0-7
Definition
Options
owner
group
other
execute
()317
write
read
add permission
- remove permission
set permission
( :)0-00 .
( :)6-00 .
.00.3
.
()318
.00.3.0
.
.
.
( ) )File Allocation Table (FAT
.DOS FAT32 .
.00.3.3
503
. ( )cluster
3149 23769 4 64
.
.
(.)cluster
.00.3.3.0 ()contiguous allocation
. 5
5 () .
.
.
()319
( )
( ) (.)7-00
( :)7-00 .
()301
( :)7-00 .
()300
( :)9-00 .
.
.00.3.3.4
.
()302
.0
.3
.2
.4
.5
.6
.7
.9
.3
allocation table
.01
()303
()304
()305
(System
)Distributed
.02.0
.
.
.
.
. ( )
.
.
.
.
.
()306
( :)0-03 .
.02.3
:
( )resources
.
.
.
.02.2
.
.
()307
(
) . .
. .
:
.
.
:
(.)monolithic
(.)modern
:
(.)DOS
(.)NOS
()308
( :)3-03
.03.2.0
.
.
.
( .)multitasking (
)
.
.
"" ""
"" "" .
.
(.)system calls
.
()309
:
( .)Kernel
( )User .
.03.2.0.0
.
.
(
).
.03.2.0.3 ()
.
.
( ( .))device registers
.
( system
.)calls .
.
. :
()321
.
.
.
:
(.)recompile
()setup
( monolithic
.)operating system :
(.)openness
(.)reliability
(.)maintainability
.03.2.3 ()modern operating system
:
.
.
(.)small microkernel
()320
( :)2-03
.03.2.3.0 ( )microkernel
.
.
(.)portable
.
.03.2.3.3 ()microkernel
.
.03.2.2
)Distributed Operating System (DOS
.
()322
:
()multiprocessors
( homogenous
.)multicomputers
:
().
/ ().
.
.03.2.4
.
.
()323
( :)4-03
(.(consistency
.
.
:
.
( ).
.
.
.
(
).
()324
.
.03.2.5
( .)simultaneous access
.03.2.6
:
()semaphore
()monitors
.03.2.6.0
:
"" (.)down
"" (.)up
.
(""):
:
.
( ) .process is blocked
(""):
() .
()325
.
"".
""
""
().
.
() ()
( )unstructured code goto .
(.)monitor
.03.2.6.3 ( )monitor
(.)procedures
( )monitor
(.)encapsulation
:
.
.
()0
()326
( )
( ).
.
()3
.x
{ Monitor mn
;int x=0
private:
public:
mn x
)(.decr() incr() value
:
.
( )procedures.
.x
()2
)( decr x
()327
)(( decr).
.
.03.2.6.2 :
()wait
(.)signal
()
.
.
( ).
cr
.
{Monitor cr
;private: int x=0
;int blocked_process=0
;Condition unblocked
public:
};int value(){ return x
{)(void incr
()328
)if(blocked_process==0
;x++
};)Signal(unblocked
else
{)(void decr
)if (x==0
;Blocked_process++
;)Wait(unblocked
;Blocked_process--
}
else
;x--
}
}
cr ( :)6-03
13.2.6.2
( )wait ( )notify .
.
.03.2.7
()329
.
. .
.
( :)7-03
:
( ).
.
.
:
.
.
()331
.
.
.
.
.03.2.7.0 ()message passing
.
.
.03.2.7.3 ()reliable communication
( )reliable
.
.
.02.4 ()DSM
DSM distributed shared memory
.systems
.
.
.
()330
( )emulating
.
( ).
:
.
( 4 9 ) .
( ).
.
:
.
.
.
( )9-03 0 3 5 3 1
.
01
01 3
0 (.)7-03
.03.4.0 DSM
DSM
(.)read only
()332
01
0 3 ( 0
) 01 0
3
.
.
.
()333
()9-03
(.)inconsistency
()334
.
( .)inconsistence
.
.
DSM .
DSM.
.03.4.3 .DSM
( setting up
)transfer .
.
.
(.)false sharing
.
. DSM
.
.02.5
.
.
()335
(.)Heterogeneous Multicomputers
( )uniprocessor ( local
)services (.)remote clients
(.)transparency
( )middleware
.
( )DOS
.
. .
.
()336
()3-03
.
.03.5.0
. :
.
.
.
:
m2:f2
Rcp m1:f1
f1 m1 m2 .f2
( )server
. ( )file server
( )clients
.
(.)01-03
()337
()01-03
(.)transparency
.03.5.3
( )transparency
:
.
:
.
( )account .
.
( )access permissions
.
.
()338
( )security
.
.03.5.2
.
.
.02.6
middleware
:
( .)independent computers
(.)single coherent system
.
.
:
.
.
.
( ).
.
()339
( .)transparence
.
( )layer
.
.03.6.0 positioning middleware
. sockets
.
( )interfaces .
( .)distribution
( )middleware .
( :)00-03
()341
( )
.
.
.
.03.6.3
.
.
( )
.
.03.6.2 ()middleware models
.
.
(.)UNIX
.03.6.4
.03.6.4.0
. .
.
.03.6.4.3 ()RPC
()340
()
( ).
.03.6.4.2 ((distributed objects invocations
()objects
( )method .
( )method
( ).
.03.6.4.4 ()distributed documents
.
( ).
. .URL
http://www.sustech.edu
:
.
.
.
.
()342
.
.
( ).
.03.6.5 ( )middleware services
:
( ) :
.
(.)RPC
( )distributed file systems
.
.
( :)naming
( )URL
.
( :)security
.
.03.6.6 ()openness
.
. .
()343
( )interface .
.
.
( )portability .
()344
.02.7
()345
()346
()347
()348
) (
)349(
()
Process
Thread
Scheduling
Deadlock
Memory
Virtual memory
Performance
Efficiency
Cluster
Multiprocessor
Multitasking
Cache memory
Main memory
Registers
Processor
Resource
Page Fault
()351
Page Replacement
Swap
Main memory
Cache memory
Device drivers
()350
) (
yoctosecond [ ys ]
zeptosecond [ zs ]
attosecond [ as ]
femtosecond [ fs ]
picosecond [ ps ]
nanosecond [ ns ]
microsecond [ s ]
0,001 [ thousandth ]
millisecond [ ms ]
0.01 [ hundredth ]
centisecond [ cs ]
1.0
second [ s ]
60 seconds
59.83617 seconds
= 1 minute [ sidereal ]
60 minutes
= 1 hour
)352(
24 hours
= 1 day
3,600 seconds
= 1 hour
86,400 seconds
86,164.09 seconds
= 1 day [ sidereal ]
7 days
= 1 week
168 hours
= 1 week
14 days
= 1 fortnight
= 1 month
365 days
= 1 year
366 days
= 1 leap year
12 months
= 1 year
31,536,000 seconds
= 1 year [ calendar ]
31,558,150 seconds
= 1 year [ sidereal ]
31,556,930 seconds
= 1 year [ tropical ]
9,460,550,000,000,000 metres
= 1 light year
= speed of light
Parsec
)353(
http://www.simetric.co.uk/si_time.htm :
)354(
()
( )
.C
:
C
( ):
( gedit ).
.
creatProcess.c
:
o cc -o creatProcess creatProcess.c
:
o ./ creatProcess
()1
>#include <stdio.h
>#include <sys/types.h
#define MAX_COUNT 200
void ChildProcess(void); /* child process prototype */
void ParentProcess(void); /* parent process prototype */
{ )void main(void
;pid_t pid
()355
pid = fork();
if (pid == 0)
ChildProcess();
else ParentProcess();
}
void ChildProcess(void) {
int i=5;
printf(" This line is from child, value = %d\n", i);
printf(" *** Child process is done ***\n");
}
void ParentProcess(void) {
int i=9;
printf("This line is from parent, value = %d\n", i);
printf("*** Parent is done ***\n");
}
)2(
)356(
fork() C++
.
#include <iostream>
#include <string>
// Required by for routine
#include <sys/types.h>
#include <unistd.h>
using namespace std;
int globalVariable = 2;
main()
{
string sIdentifier;
int
iStackVariable = 20;
pid_t pID = fork();
if (pID == 0)
// child
{
// Code only executed by child process
sIdentifier = "Child Process: ";
globalVariable++;
iStackVariable++;
}
else if (pID < 0)
// failed to fork
{
cerr << "Failed to fork" << endl;
exit(1);
// Throw exception
}
else
// parent
{
// Code only executed by parent process
sIdentifier = "Parent Process:";
}
// Code executed by both parent and child.
cout << sIdentifier;
cout << " Global variable: " << globalVariable;
)357(
cout << " Stack variable: "
)3(
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main() {
pid_t pid; /* * /
char *message;
int n;
printf("fork program starting");
()
pid = fork();
switch(pid) {
case -1: exit(1);
case 0: message = "this is the child process"; n = 3;
break;
default: message = "this is the parent process"; n = 6;
break;
}
for(; n > 0; n-) {
puts(message);
sleep(1);
}
exit(0);
)358(
}
fork
:
;)(pid = fork
pid (
( ))unique
.pid
.-1
:
kill -9 [PID] $
PID 0227
:
$ $kill -9 1337
C:
;) kill( 1337, SIGKILL
()4
)( fork
execlp exec . )(.exit
wait .
)(int main
{
()359
pid_t pid;
/* fork another process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed");
exit(-1);
}
else if (pid == 0) { /* child process */
execlp("/bin/ls", "ls", NULL);
}
else { /* parent process */
/* parent will wait for the child to complete */
wait (NULL);
printf ("Child Complete");
exit(0);
}
}
)5(
)361(
()360
Hello 2 12 Hello 1 8 . fork
)( funct .for
. .
()6
C child1
)( .fork .child2
. 3
child1 4 child2
.5
. .
;)(int pid = fork
{)if (pid==0
;)(pid=fork
{ )if (pid==0
;)printf(child 2 %d \n", 3*3
)(exit
()362
}
printf("child2 %d\n", 4*4);
exit();
}
Printf("parent %d\n", 5*5);
Wait(NULL);}
. :Wait()
)6(
:
int pid=fork()
if (pid==0){
while(1)
printf("child");
} else {
while(1)
printf("Parent ");}
)363(
()
8.01 9.14
:
()364
( )
Demo and full Installation
:
()365
()live CD
( : )Try Ubuntu
( )live CD .
( )Install Ubuntu
.
( )partition (
- ( )computer management
C.
.
( C) (
C ).
()366
( )new partition
Acronis PartitionExpert
.Partition magic
C D C (
.
Install Ubuntu (
) :
.0 ( )English.
.3 ( ) ().
()367
.2 (
) Arabic -> Arabic-qwert/digits
.4 :
()368
.a manual
.b :
()369
.c ( )E D c
E Delete
.partition
.d ( )free space
()371
.e ()
2000 )4111 ()swap
.
.f
( )
" "/
.
.g :
()370
.5 .
.6 windows XP
( ).
()372
.7 .
.9 .
.3 .
()373
.01 :
.
:
:
:swap
.
:/
.
()374
( )
( )01GB
Install inside windows :
( )language
( ) ( )installation drive
( )installation size ( )user name
( )password . .install
:
()375
()376
()377