1 / 20

Ch4. Processes

Ch4. Processes. 2014-09-27. new. terminate. admitted. exit. pointer. process state. interrupt. process number. ready. running. program counter. register. scheduler dispatch. Memory limits. I/O or event completion. waiting. I/O or event wait. List of open files.

jane
Télécharger la présentation

Ch4. Processes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ch4. Processes 2014-09-27.

  2. new terminate admitted exit pointer process state interrupt process number ready running program counter register scheduler dispatch Memory limits I/O or event completion waiting I/O or event wait List of open files Diagram of process state Process control block 4.1 Process Concept (1)

  3. 4.1 Process Concept (2) Diagram showing CPU switch from process to process. process P0 Operating system process P1 Interrupt or system call executing Save state into PCB0 idle reload state from PCB1 executing idle Interrupt or system call Save state into PCB1 idle reload state from PCB0 executing

  4. Process B Process A Idle; input Idle; input Idle; input Idle; input Idle; input Idle; input start start stop stop Process P0 Idle; input Idle; input Idle; input start stop Process P1 Idle; input Idle; input Idle; input start stop 4.2 Process Scheduling (1) • CPU utilization and higher throughput • Two processes, A and B, for execution • Process execution with multiprogramming

  5. High level scheduling Intermediate level scheduling Job Submit HOLD Low-level scheduling Ready Queue CPU I/O I/O Queue I/O Request time slice expired Child terminate Child executes Fork a child Interrupt occurs Wait for an interrupt 4.2 Process Scheduling (2) • Process scheduling

  6. 4.2 Process Scheduling (3) • 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. swap in swap out partially executed swapped-out processes CPU END Ready Queue I/O waiting Queue I/O 4.2 Process Scheduling (4) Addition of medium-term scheduling to the queuing diagram

  8. 4.3 Operation on Process (1) Process Creation • O.S. mechanism Process Termination • Process Graph : Graph for the relation of several processes Example) P1 P3 P2 P4 P5 P6 Pi-> Pj : node Pi is parent of Pj Pj is child of Pi -> : edge means that “Pi create Pj”

  9. 4.3 Operation on Process (2) • 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 • 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. 4.3 Operation on Process (3) • Process creation (parent process  childern) Fork S1 ; Fork L ; S2 ; L :S3 ; Join Fork L1 ; S1 ; ¦ Go To L2 ; ¦ L1 :S2 ; L2 :Join Count ; S1 Fork S2 S3 S1 S2 Join S3

  11. 4.3 Operation on Process (4) ex) Concurrent Count := 2 Fork L1 ; read(a) ; Go to L2 ; L1 : read(b) ; L2 : Join count ; c := a+b ; write(c) ; read(a) ; read(b) ; c := a+b ; write(c) ; S1 ; count := 3 ; Fork L1 ; S2 ; S4 ; Fork L2 ; S5 ; Go To L3 ; L2 : S6 ; Go To L3 ; L1 : S3 ; L3 : Join count ; S7 ; s1 s2 s3 s4 s6 s5 s7

  12. 4.4 ~ 4.5. Cooperating Process / Threads • Cooperating Process: Process that shares data with other processes • Task >> Thread a basic unit of CPU utilization =Light weight process a group of thread =heavy weight process * Traditional process : a task with one thread. UNIX Kernel : Single Tasking. MACH Kernel : multithread. • Producer & Consumer Processes ex) Assembly code Object Modules • Bounded Buffer / Unbounded - Buffer Producer . Compiler Assembler Loader

  13. 4.4 Cooperating Process • Concurrent processes • Independent processes : cannot affect the other processes • Cooperating processes : share data with other processes • Why cooperating? • Information sharing • Computation speedup • Modularity • convenience

  14. 4.4 Cooperating Process • 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 < fork / join > < parbegin / parend >

  15. P1 P2 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 P1(i) and P2(i-1) concurrently P1(i) P2(i)

  16. 4.6 InterProcess Communication • Communication of Cooperating process • Shared Memory • IPC(method of Message communication) • IPC operation : Send, Receive • Consideration Issues • How many links • buffer space • Message size • unidirectional / bidirectional Send MSG P Q Receive MSG

  17. 4.6 Interprocess Communication • Communication link • Naming • Direct Communication • Indirect Communication • 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 • Indirect communication : by mailbox(ports) • Send(A,MSG) : send a MSG to mailbox A • Receive(A,MSG) : Receive a MSG from mailbox A • 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

More Related