Download presentation
Presentation is loading. Please wait.
Published byJoanna Wood Modified over 9 years ago
1
cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4
2
cs431-cotter2 Process Management A program is an algorithm or a plan A process is a program in execution –dynamic –program is static process == job Process includes: –program counter –stack –data section –etc.
3
cs431-cotter3 Figure 2-1. (a) Multiprogramming of four programs. (b) Conceptual model of four independent, sequential processes. (c) Only one program is active at once. The Process Model Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
4
cs431-cotter4 Events which cause process creation: System initialization. Execution of a process creation system call by a running process. A user request to create a new process. Initiation of a batch job. Process Creation Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
5
cs431-cotter5 Events which cause process termination: Normal exit (voluntary). Error exit (voluntary). Fatal error (involuntary). Killed by another process (involuntary). Process Termination Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
6
cs431-cotter6 Two State Process Model Simplest concept of process management –running –not running Dispatcher can switch between jobs in the queue. –Works well if all jobs in the queue are always ready to execute. –If not, additional states are needed.
7
cs431-cotter7 Figure 2-2. A process can be in running, blocked, or ready state. Transitions between these states are as shown. Process States Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
8
cs431-cotter8 Process State Diagram States: New, Running, Waiting, Ready, Terminated new ready running terminated waiting admitted interrupt dispatch I/O compI/O req exit
9
cs431-cotter9 Process State Diagram (alternate view) States: New, Running, Ready, suspended, Blocked, Terminated new ready running terminated blocked admitted interrupt dispatch activate event wait exit suspend activate suspend event occurs
10
cs431-cotter10 Figure 2-3. The lowest layer of a process-structured operating system handles interrupts and scheduling. Above that layer are sequential processes. Implementation of Processes (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
11
cs431-cotter11 Process Schedulers Ready queue CPU Simple system Next Level of detail Ready queue CPU wait queue
12
cs431-cotter12 Process Schedulers Realistic System ready queue CPU wait queueI/O queue I/O time slice expired fork child wait for interrupt child executes interrupt occurs job queue
13
cs431-cotter13 Process Schedulers Long Term Scheduler –Controls loading of processes into the ready queue. –Determines the degree of multi-programming allowed in the system (how many processes are active at one time) –Operates infrequently (seconds) Short Term Scheduler –Controls loading of processes into CPU. –Operates more frequently (milliseconds)
14
cs431-cotter14 Figure 2-4. Some of the fields of a typical process table entry. Implementation of Processes (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
15
cs431-cotter15 Process Control Block pointer process state process number program counter registers memory limits open files Etc...
16
cs431-cotter16 Process Switching Context Switching Operating System Process 1 PCB Save to PCB1 Save to PCB2 Reload PCB2 Reload PCB1 Process 2 PCB
17
cs431-cotter17 Figure 2-5. Skeleton of what the lowest level of the operating system does when an interrupt occurs. Implementation of Processes Interrupt Processing Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
18
cs431-cotter18 Figure 2-6. CPU utilization as a function of the number of processes in memory. Modeling Multiprogramming Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
19
cs431-cotter19 Figure 2-11. (a) Three processes each with one thread. (b) One process with three threads. The Classical Thread Model (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
20
cs431-cotter20 Figure 2-12. The first column lists some items shared by all threads in a process. The second one lists some items private to each thread. The Classical Thread Model (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
21
cs431-cotter21 Figure 2-13. Each thread has its own stack. The Classical Thread Model (3) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
22
cs431-cotter22 Figure 2-7. A word processor with three threads. Thread Usage (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
23
cs431-cotter23 Figure 2-8. A multithreaded Web server. Thread Usage (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
24
cs431-cotter24 Figure 2-9. A rough outline of the code for Fig. 2-8. (a) Dispatcher thread. (b) Worker thread. Thread Usage (3) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
25
cs431-cotter25 Figure 2-10. Three ways to construct a server. Thread Usage (4) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
26
cs431-cotter26 Thread Types Kernel Threads –Small data structure / stack. –Thread switching does not affect memory access info –relatively fast User Threads –Only need to switch PC and stack info –Operate above (and independent of) kernel –very fast Hybrid (both) –Uses LWP to package user threads for kernel control
27
cs431-cotter27 Figure 2-16. (a) A user-level threads package. (b) A threads package managed by the kernel. Implementing Threads in User Space Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
28
cs431-cotter28 Figure 2-17. Multiplexing user-level threads onto kernel-level threads. Hybrid Implementations Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
29
cs431-cotter29 Threads in Solaris 2 CPU kernel thread user thread LWP kernel task 1task 3task 2
30
cs431-cotter30 Figure 2-18. Creation of a new thread when a message arrives. (a) Before the message arrives. (b) After the message arrives. Pop-Up Threads Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
31
cs431-cotter31 Figure 2-19. Conflicts between threads over the use of a global variable. Making Single-Threaded Code Multithreaded (1) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
32
cs431-cotter32 Figure 2-20. Threads can have private global variables. Making Single-Threaded Code Multithreaded (2) Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
33
cs431-cotter33 Summary Operating systems are designed to run processes –They provide a framework to run multiple processes in parallel, efficiently –Processes are implemented to be independent of each other Processes may have multiple threads –Threads share a process context –Threads often interact with each other
34
cs431-cotter34 Questions What is the difference between a thread and a process. Given that a task might be implemented using either a new thread or a new process, discuss some of the factors that might suggest one form over the other. (When would a process be good and when would a thread be good?) What is the difference between a kernel thread and a user space thread? What is the advantage of a user space thread? What is its disadvantage? What types of events might move a process from a running state to a ready state? Why is it more efficient to run (schedule) multiple processes in parallel rather than to just run them as serial (sequential) processes? What types of events might preempt a thread that is executing in the CPU? (What events might make it change state?)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.