Download presentation
Presentation is loading. Please wait.
Published byAldous Hutchinson Modified over 8 years ago
1
2 October 2008CIS 340 # 1 Last Covered Sophistication of OS control into process control Closure on processes Quiz
2
2 October 2008CIS 340 # 2 Topics To review your Project 1 (continuing) To understand the operating system Basic responsibilities Standard enhancements –Process management »tasks, roles, versions –Thread distribution –Interrupt-handling Distributed processing support –Communication aspects
3
2 October 2008CIS 340 # 3 OS Key Elements
4
2 October 2008CIS 340 # 4 Process A program in execution Three components 1.An executable program 2.Associated data needed by the program context 3.Execution context of the program –All information needed to manage the process »Program counter »Stack »Data section
5
2 October 2008CIS 340 # 5 State Diagram of a Process:5 States What is the structure of a process?
6
2 October 2008CIS 340 # 6 Process Control Block (PCB): Data Structure Holds information associated with each process One for each process 1.Process state 2.Program counter 3.CPU registers 4.CPU scheduling information 5.Memory-management information 6.Accounting information 7.I/O status information
7
2 October 2008CIS 340 # 7 Process Control Information: Scheduling & State Information via PCB Information needed by the operating system to perform its scheduling function Process state: ready, waiting …. Priority: Attribute describing scheduling priority default, current, highest-allowable Scheduling-related information: Relative to scheduling algorithm used duration delayed, duration last executed Event: Identity of event process needs to resume execution
8
2 October 2008CIS 340 # 8 EX: CPU Switch From Process to Process How are processes handled?
9
2 October 2008CIS 340 # 9 Process Scheduling == Queue Handling Achieved by process migration among queues Job queue Set of all processes in the system Ready queue Set of all processes residing in main memory Ready and waiting to execute Device queues Set of processes waiting for an I/O device
10
2 October 2008CIS 340 # 10 Consider A process is ____ a)Equivalent to a program b)A queue to be controlled c)A program in execution d)Decomposable into segments e)None of the above
11
2 October 2008CIS 340 # 11 EX: Process Scheduling Pathways
12
2 October 2008CIS 340 # 12 EX: Ready Queue And Various I/O Device Queues
13
2 October 2008CIS 340 # 13 Schedulers Long-term scheduler Aká job scheduler Selects processes to enter the ready queue Controls the degree of multiprogramming Invoked very infrequently (seconds, minutes) may be slower Short-term scheduler Aká CPU scheduler Selects process to be executed next Allocates CPU to the process Invoked very frequently (milliseconds) must be fast
14
2 October 2008CIS 340 # 14 FYI: Addition of Medium Term Scheduling
15
2 October 2008CIS 340 # 15 Context Switch When CPU switches to another process State of the “old process” saved Load the saved state of the “new process” “out with the old, in with the new” Time dedicated to switching is overhead No “useful work” while switching No program execution Hardware speedsHardware speeds influence time to provide the context switch effortDef: Is process manipulation costly?
16
2 October 2008CIS 340 # 16 Process Creation Parent process creates children processes In turn create other processes Tree of processes Resource sharing POSSIBILITIES –Parent and children share all resources –Children share subset of parent’s resources –Parent and child share no resources Execution POSSIBILITIES –Parent and children execute concurrently –Parent waits until children terminate Address space POSSIBILITIES –Child duplicates parent –Child has a distinct program
17
2 October 2008CIS 340 # 17 EX: Process Creation: UNIX fork –System call creating new process exec –System call used after a fork –Replaces the process’s memory space with a new program
18
2 October 2008CIS 340 # 18 Process Termination Process executes last statement –Requests operating system to delete exit system call –Output / “returned data” from child to parent wait system call –Process’ resources are deallocated by operating system Parent may terminate execution of children processes abort system call –Child has exceeded allocated resources –Task assigned to child is no longer required –Parent is exiting If a parent terminates, children must terminate Cascading termination
19
2 October 2008CIS 340 # 19 Concurrent Processes: Two Types 1.Independent –Cannot affect or be affected by other processes executing in the system –If does not share data 2.Cooperating –Can affect or be affected by the execution of another process Advantages (process cooperation) –Information sharing e.g. Access to same file –Computation speed-up e.g. Some form of parallelism –Modularity e.g. subunits of processes or threads –Convenience Allows user to multitaskDef:
20
2 October 2008CIS 340 # 20 EX: Producer-Consumer Problem Paradigm for cooperating processes producer process produces information consumer process consumes it unbounded-buffer places no practical limit on buffer size bounded-buffer assumes a fixed buffer size
21
2 October 2008CIS 340 # 21 Bounded-Buffer – Shared-Memory Solution Shared data #define BUFFER_SIZE 10 Typedef struct {... } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; When in == out :: buffer empty in next free position out first full position Solution is correct, but can only use BUFFER_SIZE-1 elements in out buffer 2 3 4 5 6 7 8 9 1 0
22
2 October 2008CIS 340 # 22 in out H buffer 2 3 4 5 6 7 8 9 1 0 nextProducedH
23
2 October 2008CIS 340 # 23 in out H buffer 2 3 4 5 6 7 8 9 1 0 nextProducedH
24
2 October 2008CIS 340 # 24 in out A D F G B C K J H buffer 2 3 4 5 6 7 8 9 1 0
25
2 October 2008CIS 340 # 25 Bounded-Buffer – Producer Process when out inin+1(in+1) % BUFFER_SIZE 0011%10 1 0233%10 3 091010%10 0 item nextProduced; /* local */ while (1) { while (((in + 1) % BUFFER_SIZE) = = out) ; /* do nothing; cannot store */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; /* moves ptr */ } Will anything be in buffer[9] – assume nothing leaves ?
26
2 October 2008CIS 340 # 26 Bounded-Buffer – Consumer Process item nextConsumed; /* local */ while (1) { while (in == out) ; /* do nothing; nothing in the queue */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* moves ptr */ } when out inout+1(out+1) % BUFFER_SIZE 0011%10 1 0233%10 3 091010%10 0
27
2 October 2008CIS 340 # 27 in out A D F G B C K J H buffer 2 3 4 5 6 7 8 9 1 0 nextConsumed
28
2 October 2008CIS 340 # 28 in out A D F G B C K J buffer 2 3 4 5 6 7 8 9 1 0 nextConsumed
29
2 October 2008CIS 340 # 29 in out A D F G B C K J buffer 2 3 4 5 6 7 8 9 1 0 nextConsumedH
30
2 October 2008CIS 340 # 30 in out A D F G B C K J buffer 2 3 4 5 6 7 8 9 1 0nextConsumedH
31
2 October 2008CIS 340 # 31 Roles for Processes What’s Next?Roles for Processes ? Reflections
32
2 October 2008CIS 340 # 32 REFLECT: Problems Arising with System Software 1.Improper synchronization –Ensure a process waiting for an I/O device receives the signal 2.Failed mutual exclusion –Memory overwrites 3.Nondeterminate program operation – Program A should only depend on input to it –Activities of other programs -- Program B, C... Z -- should not influence Program A ’s outcome 4.Deadlocks
33
2 October 2008CIS 340 # 33 Modern Operating Systems: Multithreading Process divided into threads –Thread –Dispatchable unit of work –Each executes sequentially –Each is interruptable –Multiple ones may work concurrently –Process –A collection of one or more threadsDef:
34
2 October 2008CIS 340 # 34 Process Have a virtual address space Holds the process image/status Handled?Protected access to processors, other processes, files, and I/O resources Has an execution state e.g. running, ready Saved thread context when not running Has an execution stack Some per-thread static storage for local variables Access to the memory and resources of its processAccess to the memory and resources of its process –All threads of a process share process Thread
35
2 October 2008CIS 340 # 35 Single and Multithreaded Processes
36
2 October 2008CIS 340 # 36 Thread Dynamics Suspending a process All threads of the process suspended WHY? All threads share the same address space Termination of a process All threads within the process terminated States –Spawn thread Spawn another –Block –Unblock –Finish Deallocate register context and stacks
37
2 October 2008CIS 340 # 37 OS Varieties MS-DOS Supports a single thread UNIX Supports multiple user processes Supports only one thread per process Windows 2000, Solaris, Linux, Mach, OS/2 Support multiple threads
38
2 October 2008CIS 340 # 38 Why Add the Complexity? Greater responsiveness Takes less time to create a new thread than a process Less time to terminate a thread than a process Less time to switch between two threads within the same process Greater resource sharing Threads within the same process share memory and files, Can communicate with each other without invoking the kernel Hence passage to kernel avoided Economy Utilization of multiprocessor architectures
39
2 October 2008CIS 340 # 39 Multithreading Models: How Does User Process Work with Kernel Process Many-to-One Many user-level threads mapped to single kernel thread Option if system does not support kernel threads One-to-One Each user-level thread maps to kernel thread EX: Windows 95/98/NT/2000 - OS/2 Many-to-Many Enables many user level threads to be mapped to many kernel threads Allows the operating system to create a sufficient number of kernel threads EX: Solaris 2 Windows NT/2000 with ThreadFiber package
40
2 October 2008CIS 340 # 40 Consider The information needed by the operating system to record the status of a process in order to continue with the execution of a process at a later time is maintained in the ___. a)Process control block b)Process memory queue c)Process buffer socket d)Process switch block e)Process cache
41
2 October 2008CIS 340 # 41 Complexity of Threading: Issues Each OS designed to handle the points Semantics of fork() and exec() system calls Thread cancellation Signal handling Thread pools Thread specific data
42
2 October 2008CIS 340 # 42 User-Level Threads W2000, Linux, and OS/2 Scheduling is done on a thread basis NOTE!!!Kernel maintains context information for the process and the threads Kernel-Level Threads Combined Strategy All thread management is done by layer “above” / “outside” kernel NOTE!!!Kernel is not aware of the existence of threads Solaris User space handles: Thread creation Bulk of scheduling Synchronization of threads
43
2 October 2008CIS 340 # 43 EX:Windows 2000 Threads One-to-one mapping Each thread contains thread id register set separate user and kernel stacks private data storage area
44
2 October 2008CIS 340 # 44 EX: Linux Threads tasksReferred as tasks Thread creation system call clone() clone() child task to shares the address space of the parent task (process)
45
2 October 2008CIS 340 # 45 EX:Solaris 2 Threads light-weight process: A single-threaded sub- process which, unlike a thread, has its own process identifier and may also differ in its inheritance and controlling features.thread process identifier Def: Solaris 2 Process
46
2 October 2008CIS 340 # 46 Different Thread Realizations
47
2 October 2008CIS 340 # 47 Can you answer? Threads / Processes How are they the same? How are they different?
48
2 October 2008CIS 340 # 48 Interrupts What’s Next?Interrupts ? Reflections
50
2 October 2008CIS 340 # 50 Migration of OS Concepts and Features through Platforms Batch TIME SHARE
51
2 October 2008CIS 340 # 51 Many-to-One Model
52
2 October 2008CIS 340 # 52 One-to-one Model
53
2 October 2008CIS 340 # 53 Many-to-Many Model
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.