Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Implementing Processes, Threads, and Resources.

Similar presentations


Presentation on theme: "Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Implementing Processes, Threads, and Resources."— Presentation transcript:

1 Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Implementing Processes, Threads, and Resources

2 Slide 6-2 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 OS Address Space OS Address Space Implementing the Process Abstraction Control Unit OS interface … Machine Executable Memory ALU CPU P i Address Space P i Address Space P i CPU P i Executable Memory P i Executable Memory P k Address Space P k Address Space … P k CPU P k Executable Memory P k Executable Memory P j Address Space P j Address Space P j CPU P j Executable Memory P j Executable Memory Ideal Abstraction: As if using an Actual machine

3 Slide 6-3 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Modern process “The value of the modern process model is that it enables the programmer to design software so that various parts of the computation can work together as a set of threads within a single modern process framework.” Classic process can work together but they do not share a customized computational framework

4 Slide 6-4 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 External View of the Process Manager Hardware Application Program Application Program Device MgrProcess MgrMemory Mgr File Mgr UNIX Device MgrProcess MgrMemory Mgr File Mgr Windows CreateThread() CreateProcess() CloseHandle() WaitForSingleObject() fork() exec() wait()

5 Slide 6-5 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Process Manager Responsibilities Define & implement the essential characteristics of a process and thread –Algorithms to define the behavior –Data structures to preserve the state of the execution Define what “things” threads in the process can reference – the address space (most of the “things” are memory locations) Manage the resources used by the processes/threads Tools to create/destroy/manipulate processes & threads Tools to time-multiplex the CPU – Scheduling the (Chapter 7) Tools to allow threads to synchronization the operation with one another (Chapters 8-9) Mechanisms to handle deadlock (Chapter 10) Mechanisms to handle protection (Chapter 14)

6 Slide 6-6 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Modern Processes and Threads OS interface … … … P i CPU Thrd j in P i Thrd k in P i …

7 Slide 6-7 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Modern Threads User Space Threads - underlying Os implements classic processes and the user space thread library executes on top of the OS abstract machine to multiprogram the threads. (Mach C and POSIX threads) Kernel Threads - OS time-multiplexes the execution of threads instead of processes. Therefore when one thread blocks the other threads can still execute. (Windows)

8 Slide 6-8 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Resources Any element of the abstract machine that a process can request and can cause the process to be blocked if not available. If device is allocated to a process then it is configured into the abstract machine for process Multiple resource managers - hardware devices, processor, abstract synch resources, primary memory, and files Each resource manager must present a common behavior described by a general model

9 Slide 6-9 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Processes &Threads Address Space Map Stack State Program Static data Resources Stack State Map

10 Slide 6-10 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 The Address Space Process Address Space Address Binding Executable Memory Other objects Files

11 Slide 6-11 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Building the Address Space Some parts are built into the environment –Files –System services Some parts are imported at runtime –Mailboxes –Network connections Memory addresses are created at compile (and run) time

12 Slide 6-12 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 The OS Abstract machine interface –Host hardware instruction set and set of functions exported by OS Unix and Windows most widely used Unix - POSIX interface (standard)

13 Slide 6-13 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Modern Process Framework Thread-based computation is executed within this framework Modern Process structure –Address space –Program –Data - shared by threads –Resources Threads share the resources that have been allocated to the process –Process Id

14 Slide 6-14 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Threads Active Element Threads –Host process environment –Thread-specific data (at least a stack) –Thread ID

15 Slide 6-15 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Tracing the Hardware Process Bootstap Loader Process Manager Interrupt Handler P1P1 P,2 PnPn … Machine is Powered up Initialization Load the kernel Service an interrupt Hardware process progress Execute a thread Schedule

16 Slide 6-16 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 The Abstract Machine Interface User Mode Instructions User Mode Instructions Application Program User Mode Instructions Abstract Machine Instructions Trap Instruction Supervisor Mode Instructions Supervisor Mode Instructions fork() create() open() OS

17 Slide 6-17 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Abstract Machine Instruction Set ALU - load, store, add… Control Unit - branch, procedure_call… Trap - create_process(), open_file()… Linux 2.4x - exports over 200 functions - 2.5 million lines of code Windows NT/2000/XP - exports over 2,000 functions - over 25 million lines of code

18 Slide 6-18 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Context Switching Process Manager Interrupt Handler P1P1 P2P2 PnPn Executable Memory Initialization 1 2 3 4 5 7 Interrupt 8 9 6

19 Slide 6-19 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Process Descriptors OS creates/manages process abstraction Descriptor is data structure for each process –Register values –Logical state –Type & location of resources it holds –List of resources it needs –Security keys –Process ID, parent process

20 Slide 6-20 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Creating a Process in UNIX pid = fork(); UNIX kernel … Process Table Process Descriptor

21 Slide 6-21 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Linux Process Descriptor

22 Slide 6-22 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Linux Process Descriptor

23 Slide 6-23 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Linux Process Descriptor

24 Slide 6-24 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 EPROCESS … void *UniqueProcessId; … NT Executive Windows NT Process Descriptor KPROCESS … uint32 KernelTime; uint32 UserTime; … Byte state; NT Kernel NT Kernel handles object management, interrupt handing, thread scheduling NT Executive handles all other aspect of a process

25 Slide 6-25 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Windows NT Process Descriptor (2)  Kernel process object includes:  Pointer to the page directory  Kernel & user time  Process base priority  Process state  List of the Kernel thread descriptors that are using this process

26 Slide 6-26 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Windows NT Process Descriptor (3)  Parent identification  Exit status  Creation and termination times.  Memory status  Security information  executable image  Process priority class used by the thread scheduler.  A list of handles used by this process  A pointer to Win32-specific information

27 Slide 6-27 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 ETHREAD Windows NT Thread Descriptor EPROCESS KPROCESS NT Kernel KTHREAD NT Executive

28 Slide 6-28 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Creating a Process in NT CreateProcess(…); Win32 Subsystem ntCreateProcess(…); … ntCreateThread(…); NT Executive NT Kernel … Handle Table Process Descriptor

29 Slide 6-29 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Windows NT Handles

30 Slide 6-30 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Thread Abstraction Process Manager has algorithms to control threads and thread descriptor (data structure) to keep track of threads. Management Tasks - Create/destroy thread - Allocate thread-specific resources - Manage thread context switching Thread Descriptor - state - execution stats - process (reference to associated process) - list of related threads - stack (reference to stack) - thread-specific resources

31 Slide 6-31 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 State of a Process/Thread State Variable - summary status of the process/thread which is located in descriptor Ready Blocked Running Start Schedule Request Done Request Allocate Simple State Diagram

32 Slide 6-32 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 UNIX State Transition Diagram Runnable Uninterruptible Sleep Running Start Schedule Request Done I/O Request Allocate zombie Wait by parent Sleeping Traced or Stopped Request I/O Complete Resume

33 Slide 6-33 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Windows NT Thread States Initialized CreateThread Ready Activate Select Standby Running Terminated Waiting Transition Reinitialize Exit Preempt Dispatch Wait Wait Complete Dispatch

34 Slide 6-34 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Resources Resource: Anything that a process can request and then become blocked because that thing is not available. Resource Descriptors - Internal resource name - Total Units - Available Units - List of available units - List of Blocked processes

35 Slide 6-35 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Resources R = {R j | 0  j < m} = resource types C = {c j  0 |  R j  R (0  j < m)} = units of R j available Reusable resource: After a unit of the resource has been allocated, it must ultimately be released back to the system. E.g., CPU, primary memory, disk space, … The maximum value for c j is the number of units of that resource Consumable resource: There is no need to release a resource after it has been acquired. E.g., a message, input data, … Notice that c j is unbounded.

36 Slide 6-36 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Using the Model There is a resource manager, Mgr(R j ) for every R j Mgr(R j ) Process p i can only request n i  c j units of reusable R j p i can request unbounded # of units of consumable R j Process p i can request units of R j if it is currently running request Mgr(R j ) can allocate units of R j to p i allocate

37 Slide 6-37 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 A Generic Resource Manager Process Resource Manager Process Blocked Processes Resource Pool request() release() Policy

38 Slide 6-38 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Process Hierarchies Initial Process System Process System Process Other Processes

39 Slide 6-39 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Process Hierarchies Parent-child relationship may be significant: parent controls children’s execution Ready-Active Blocked-Active Running Start Schedule Request Done Request Allocate Ready-Suspended Blocked-Suspended Suspend Yield Allocate Suspend Activate

40 Slide 6-40 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Process Manager Overview Program Process Abstract Computing Environment File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process Description CPU Other H/W Scheduler Resource Manager Resource Manager Resource Manager Resource Manager Resource Manager Resource Manager Memory Devices

41 Slide 6-41 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 UNIX Organization System Call Interface File Manager Memory Manager Device Manager Protection Deadlock Synchronization Process Description Process Description CPU Other H/W Scheduler Resource Manager Resource Manager Resource Manager Resource Manager Resource Manager Resource Manager Memory Devices Libraries Process Monolithic Kernel

42 Slide 6-42 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Windows NT Organization Processor(s)Main MemoryDevices Libraries Process Subsystem User Subsystem Hardware Abstraction Layer NT Kernel NT Executive I/O Subsystem T T T T T T TT T


Download ppt "Slide 6-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 6 Implementing Processes, Threads, and Resources."

Similar presentations


Ads by Google