Download presentation
Presentation is loading. Please wait.
Published byDestin Dee Modified over 9 years ago
1
Ch4. Processes 2015-04-15.
2
4.1 Process Concept (1) new waiting terminate readyrunning admitted interrupt exit scheduler dispatch I/O or event completion I/O or event wait Diagram of process state Process control block pointer process state process number program counter register Memory limits List of open files
3
4.1 Process Concept (2) Diagram showing CPU switch from process to process. process P 0 process P 1 Operating system Interrupt or system call Save state into PCB 0 reload state from PCB 1 Save state into PCB 1 reload state from PCB 0 executing idle executing idle Interrupt or system call
4
4.2 Process Scheduling (1) F CPU utilization and higher throughput Two processes, A and B, for execution Process execution with multiprogramming Idle; input start Process A Idle; input Idle; input stop Idle; input start Process B Idle; input Idle; input stop Idle; input start Process P 0 Idle; input Idle; input stop Idle; input start Process P 1 Idle; input Idle; input stop
5
4.2 Process Scheduling (2) F Process scheduling Job SubmitHOLD Ready Queue I/O Request time slice expired Fork a child Wait for an interrupt CPU I/OI/O Queue Child executes Interrupt occurs Child terminate High level scheduling Intermediate level scheduling Low-level scheduling
6
4.2 Process Scheduling (3) F Scheduling Algorithm High Level Scheduling by Spooler Intermediate Level Scheduling = job scheduling = Long-term scheduler Low Level Scheduling = process scheduling =short-term scheduler ( CPU )
7
Addition of medium-term scheduling to the queuing diagram partially executed swapped-out processes swap inswap out Ready Queue CPUEND I/O waiting Queue I/O 4.2 Process Scheduling (4)
8
4.3 Operation on Process (1) F O.S. mechanism Process Creation Process Termination F Process Graph : Graph for the relation of several processes Example) P1P1 P3P3 P2P2 P4P4 P5P5 P6P6 P i -> P j : node P i is parent of P j P j is child of P i -> : edge means that “ P i create P j ”
9
4.3 Operation on Process (2) F Process Creation Execution ① Parent runs concurrently with children ② Parent waits until some or all of its children have terminated Sharing Parent shares all common resources with child F Process Termination Parent terminate the execution of children if child use allocated resource excessively task that assigned to child is over cascading termination : if parent terminated, children terminated
10
F Process creation (parent process childern) Fork S 1 ; Fork L ; S 2 ; L : S 3 ; Join Fork L 1 ; S 1 ; ¦ Go To L 2 ; ¦ L 1 : S 2 ; L 2 : Join Count ; S1 S2S3 Fork S1S2 S3 Join 4.3 Operation on Process (3)
11
ex) Concurrent read(a) ; read(b) ; c := a+b ; write(c) ; Count := 2 Fork L 1 ; read(a) ; Go to L 2 ; L 1 : read(b) ; L 2 : Join count ; c := a+b ; write(c) ; s1s1 s2s2 s3s3 s4s4 s6s6 s5s5 s7s7 S 1 ; count := 3 ; Fork L 1 ; S 2 ; S 4 ; Fork L 2 ; S 5 ; Go To L 3 ; L 2 : S 6 ; Go To L 3 ; L 1 : S 3 ; L 3 : Join count ; S 7 ; 4.3 Operation on Process (4)
12
4.4 ~ 4.5. Cooperating Process / Threads F Cooperating Process: Process that shares data with other processes F Task >> Thread a basic unit of CPU utilization =Light weight process a group of thread =heavy weight process * T raditional process : a task with one thread. UNIX Kernel : Single Tasking. MACH Kernel : multithread. F Producer & Consumer Processes ex) Assembly code Object Modules F Bounded Buffer / Unbounded - Buffer Producer. CompilerAssembler Loader
13
4.4 Cooperating Process F Concurrent processes Independent processes : cannot affect the other processes Cooperating processes : share data with other processes F Why cooperating? Information sharing Computation speedup Modularity convenience
14
4.4 Cooperating Process F Represent program that copy file f g with concurrent Stmt fork/join and parbegin/parend statement Var f, g : file of T; r, s : T; count : integer; begin reset(f); read(f,r); while not eof(f) do begin count:=2 s:=r fork L1; write(g,s); go to L2; L1:read(f,r); L2:join count; end write(g,r); end Var f, g : file of T; r, s : T; count : integer; begin reset(f); read(f,r); while not eof(f) do begin s:=r parbegin write(g,s); read(f,r); parend end write(g,r); end
15
4.4 Cooperating process Ex) parbegin read(a); read(b); parend c:=a+b; write(c); Problem) for i=1,5 x(i)=x(i-1)+y(i-1) y(i)=x(i-1) y(i-1) s(i)=x(i)+y(i) if s(i)>100 then a=a+1 else b=b+1 end execute P 1 (i) and P 2 (i-1) concurrently P 1 (i) P 2 (i) P1P1 P2P2
16
PQ Send MSG Receive MSG 4.6 InterProcess Communication F Communication of Cooperating process Shared Memory IPC(method of Message communication) F IPC operation : Send, Receive F Consideration Issues How many links buffer space Message size unidirectional / bidirectional
17
4.6 Interprocess Communication F Communication link F Naming Direct Communication Indirect Communication F direct Communication send(P,message) : Send a message to process P receive(Q,message) : Receive a message to process Q ex) Producer-Consumer Problem The producer process Repeat ……. Produce an item in nextp ……. Until false;
18
4.6 Interprocess Communication The consumer process Repeat receive(procedure,nextc); ……. Consume the item in nextc ……. Until false; send(P.MSG) : send a MSG to process P receive(id,MSG) : Receive a MSG from any process
19
4.6 Interprocess Communication F Indirect communication : by mailbox(ports) Send(A,MSG) : send a MSG to mailbox A Receive(A,MSG) : Receive a MSG from mailbox A F Buffering by Queue Capacity for link Zero Capacity : maximum length Zero MSG system = Rendezvous
20
4.6 Interprocess Communication Bounded Capacity : finite length if full, sender wait Unbounded Capacity : Sender is never delayed ex) P -- (MSG) -->Q P Q Send(Q,MSG) Receive(P,MSG) Receive(Q,MSG) Send(P,”ACK”) Asynchrouously
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.