Download presentation
Presentation is loading. Please wait.
Published byDavid Rich Modified over 9 years ago
1
Operating Systems Unit 2: – Process Context switch Interrupt Interprocess communication – Thread Thread models Operating Systems
2
COP 5994 - Operating Systems2 Definition of Process Set of steps Performance of a task A program in execution
3
COP 5994 - Operating Systems3 Definition of Process Process is –Identifiable Entity with properties Text region –Stores the code that the processor executes Data region –Stores variables and dynamically allocated memory Stack region –Stores instructions and local variables for active procedure calls
4
COP 5994 - Operating Systems4 Process State Transition Diagram begin end
5
COP 5994 - Operating Systems5 … with Suspend and Resume
6
COP 5994 - Operating Systems6 Process Management OS functionality: –Create process –Dispatch process –Block/wakeup process –Suspend/resume process –Terminate process Also: –Change process attributes –Enable Interprocess communication
7
COP 5994 - Operating Systems7 Process Control Blocks Execution context
8
COP 5994 - Operating Systems8 Context Switch stop a running process and start a ready process –Save execution context of running process –Load ready process’s execution context
9
COP 5994 - Operating Systems9 Context Switch
10
COP 5994 - Operating Systems10 Context Switch Switch must be transparent to process Effort for switch must be minimized –hardware support: Special PCB register to help save/restore Processor is given PCB and perform switch without software intervention
11
COP 5994 - Operating Systems11 Interrupt Get attention of processor –enable reaction to signals from hardware –may be initiated by a running process: trap E.g. dividing by zero or referencing protected memory –may be caused by external event Asynchronous with the operation of the process E.g., a keyboard key is pressed, or mouse is moved Alternative: polling
12
COP 5994 - Operating Systems12 Interrupt Processing 1.Processor is running a process 2.Interrupt occurs: current instruction is completed 3.Processor determines nature of interrupt 4.Process executes context switch to interrupt handler 5.Interrupt handler executes to completion 6.Next ready process is dispatched
13
COP 5994 - Operating Systems13 Interrupt Processing
14
COP 5994 - Operating Systems14 Interrupt Classes Interrupts are system specific IA-32 Pentium architecture: Interrupts –Hardware: from devices external to a processor –Software: to enable system calls Exceptions –error has occurred: hardware or software instruction –Terms: fault, trap or abort
15
COP 5994 - Operating Systems15 IA32 Hardware Interrupt Classes
16
COP 5994 - Operating Systems16 IA32 Exception Classes
17
COP 5994 - Operating Systems17 Interprocess Communication Process to process communication –Signal –Message
18
COP 5994 - Operating Systems18 Signals Software interrupts –Limited data exchange –Processes may catch, ignore or mask a signal Catch: run specific function on signal Ignore: let OS run default function Mask: prevent signal from occurring
19
COP 5994 - Operating Systems19 Message Passing Send and receive functionality Issues: –One directional 1 sender, n receiver(s) –Blocking or non –Implementation: pipe or memory mapping –Security Link reliability Partner authentication
20
COP 5994 - Operating Systems20 ? Process is useful concept –to structure operating system –Also: for any complex software Thread concept –Introduces two-level process concept
21
COP 5994 - Operating Systems21 Motivation for Threads Threads have become prominent in: –Software design More naturally expresses inherently parallel tasks –Performance Scales better to multiprocessor systems –Cooperation Shared address space incurs less overhead than IPC
22
COP 5994 - Operating Systems22 Thread definition Lightweight process (LWP) Thread of instructions or thread of control –Shares address space and other global information with its process –Registers, stack, signal masks and other thread-specific data are local to each thread
23
COP 5994 - Operating Systems23 Thread vs. Process
24
COP 5994 - Operating Systems24 Thread State Transition Diagram
25
COP 5994 - Operating Systems25 Thread Operations Thread and process share common operations Thread specific operations: –Cancel Signals thread to terminate: thread can mask the cancellation signal –Join Thread joins another thread: allows a thread to sleep until joined thread ends
26
COP 5994 - Operating Systems26 Threading Models User-level threads Kernel-level threads Combination of user- and kernel-level threads
27
COP 5994 - Operating Systems27 User-level Threads Threading operations occur in user space Threads are created by runtime libraries Many-to-one mapping: –User sees multiple threads –OS sees one process
28
COP 5994 - Operating Systems28 User-level Threads
29
COP 5994 - Operating Systems29 User-level Threads Many-to-one thread mapping –Advantage: User-level scheduling performance tuning avoids OS context switch more portable –Disadvantage: one process for OS All threads in process will block as a whole Cannot be scheduled on multiple processors
30
COP 5994 - Operating Systems30 Kernel-level Threads Each thread has own execution one-to-one mapping: –User and OS see multiple threads
31
COP 5994 - Operating Systems31 Kernel-level Threads
32
COP 5994 - Operating Systems32 Kernel-level Threads one-to-one thread mapping –Advantage Threads can run concurrently on multi processors: increased scalability and interactivity –Disadvantages: context switching overhead reduced portability
33
COP 5994 - Operating Systems33 Combining User- and Kernel-level Threads m-to-n thread mapping:
34
COP 5994 - Operating Systems34 Combining User- and Kernel-level Threads Thread pool –Set of persistent worker kernel threads –Improves performance in environments where threads are frequently created and destroyed –Each new thread is executed by a worker thread
35
COP 5994 - Operating Systems35 Combining User- and Kernel-level Threads Scheduler activation –Meant to address limitations of user-level threads Kernel thread block, blocks all user threads Multiple user threads in kernel thread cannot execute concurrently on multi processor –Upcall: OS calls a user-level threading library that determines if any of its threads need rescheduling
36
COP 5994 - Operating Systems36 Thread Implementation Considerations Signal delivery –Synchronous: Occur as a direct result of program execution Should be delivered to currently executing thread –Asynchronous Occur due to an event typically unrelated to the current instruction Threading library must determine each signal’s recipient so that asynchronous signals are delivered properly
37
COP 5994 - Operating Systems37 Thread Signal Delivery
38
COP 5994 - Operating Systems38 Example: UNIX Process
39
COP 5994 - Operating Systems39 Example: Unix threads POSIX Pthreads: –User level thread library Linux threads: –Task: process and thread –Fork vs. Clone system call specify which resources to share with the child thread
40
COP 5994 - Operating Systems40 Agenda for next week: Chapter 5 & 6 –Concurrency Issues Read ahead !
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.