1 / 42

Implementing Processes, Threads, and Resources

Implementing Processes, Threads, and Resources. P i CPU. P j CPU. P k CPU. …. P i Executable Memory. P j Executable Memory. P k Executable Memory. P i Address Space. P k Address Space. P j Address Space. Implementing the Process Abstraction. Ideal Abstraction:

lottie
Download Presentation

Implementing Processes, Threads, and Resources

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. Implementing Processes, Threads, and Resources Operating Systems: A Modern Perspective, Chapter 6

  2. Pi CPU Pj CPU Pk CPU … Pi Executable Memory Pj Executable Memory Pk Executable Memory Pi Address Space Pk Address Space Pj Address Space Implementing the Process Abstraction Ideal Abstraction: As if using an Actual machine OS interface OSAddress Space CPU ALU Machine Executable Memory Control Unit … Operating Systems: A Modern Perspective, Chapter 6

  3. 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 Operating Systems: A Modern Perspective, Chapter 6

  4. CreateThread() CreateProcess() CloseHandle() WaitForSingleObject() Device Mgr Process Mgr Memory Mgr File Mgr Windows External View of the Process Manager Application Program fork() wait() exec() Device Mgr Process Mgr Memory Mgr File Mgr UNIX Hardware Operating Systems: A Modern Perspective, Chapter 6

  5. 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) Operating Systems: A Modern Perspective, Chapter 6

  6. Thrdj in Pi Thrdk in Pi … Modern Processes and Threads … Pi CPU … … OS interface Operating Systems: A Modern Perspective, Chapter 6

  7. 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) Operating Systems: A Modern Perspective, Chapter 6

  8. 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 Operating Systems: A Modern Perspective, Chapter 6

  9. State Stack Stack Map Processes &Threads State Map Address Space Program Static data Resources Operating Systems: A Modern Perspective, Chapter 6

  10. Files Other objects The Address Space Executable Memory Address Space Address Binding Process Operating Systems: A Modern Perspective, Chapter 6

  11. 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 Operating Systems: A Modern Perspective, Chapter 6

  12. 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) Operating Systems: A Modern Perspective, Chapter 6

  13. 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 Operating Systems: A Modern Perspective, Chapter 6

  14. Threads • Active Element • Threads • Host process environment • Thread-specific data (at least a stack) • Thread ID Operating Systems: A Modern Perspective, Chapter 6

  15. Load the kernel Initialization Execute a thread Schedule Service an interrupt Tracing the Hardware Process Machine is Powered up Bootstap Process Manager Interrupt Handler P1 P,2 Pn Loader … Hardware process progress Operating Systems: A Modern Perspective, Chapter 6

  16. Trap Instruction fork() open() create() OS Supervisor Mode Instructions The Abstract Machine Interface Application Program Abstract Machine Instructions User Mode Instructions User Mode Instructions Operating Systems: A Modern Perspective, Chapter 6

  17. 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 Operating Systems: A Modern Perspective, Chapter 6

  18. 1 Initialization 7 8 Interrupt 2 3 4 9 5 6 Context Switching Executable Memory Process Manager Interrupt Handler P1 P2 Pn Operating Systems: A Modern Perspective, Chapter 6

  19. 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 Operating Systems: A Modern Perspective, Chapter 6

  20. Creating a Process in UNIX pid = fork(); UNIX kernel Process Table … Process Descriptor Operating Systems: A Modern Perspective, Chapter 6

  21. Linux Process Descriptor Operating Systems: A Modern Perspective, Chapter 6

  22. Linux Process Descriptor Operating Systems: A Modern Perspective, Chapter 6

  23. Linux Process Descriptor Operating Systems: A Modern Perspective, Chapter 6

  24. EPROCESS NT Executive … void *UniqueProcessId; … 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 Operating Systems: A Modern Perspective, Chapter 6

  25. 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 Operating Systems: A Modern Perspective, Chapter 6

  26. 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 Operating Systems: A Modern Perspective, Chapter 6

  27. ETHREAD EPROCESS KPROCESS Windows NT Thread Descriptor KTHREAD NT Kernel NT Executive Operating Systems: A Modern Perspective, Chapter 6

  28. Creating a Process in NT CreateProcess(…); Win32 Subsystem ntCreateProcess(…); … ntCreateThread(…); NT Executive Handle Table NT Kernel … Process Descriptor Operating Systems: A Modern Perspective, Chapter 6

  29. Windows NT Handles Operating Systems: A Modern Perspective, Chapter 6

  30. 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 Operating Systems: A Modern Perspective, Chapter 6

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

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

  33. Windows NT Thread States CreateThread Terminated Initialized Reinitialize Activate Dispatch Exit Wait Waiting Ready Running Wait Complete Wait Complete Select Preempt Transition Dispatch Standby Operating Systems: A Modern Perspective, Chapter 6

  34. 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 Operating Systems: A Modern Perspective, Chapter 6

  35. Resources R = {Rj | 0  j < m} = resource types C = {cj 0 |  RjR (0  j < m)} = units of Rj 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 cj 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 cj is unbounded. Operating Systems: A Modern Perspective, Chapter 6

  36. Process pi can request units of Rj if it is currently running pi can only request ni cj units of reusable Rj pi can request unbounded # of units of consumable Rj • Mgr(Rj) can allocate units of Rj to pi request allocate Using the Model • There is a resource manager, Mgr(Rj) for every Rj Mgr(Rj) Process Operating Systems: A Modern Perspective, Chapter 6

  37. Process Process Process A Generic Resource Manager Resource Manager Blocked Processes Policy request() Process release() Resource Pool Operating Systems: A Modern Perspective, Chapter 6

  38. Process Hierarchies Initial Process System Process Other Processes System Process Operating Systems: A Modern Perspective, Chapter 6

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

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

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

  42. Windows NT Organization Process Process T T Process T T T T Libraries T T T Subsystem Subsystem Subsystem User I/O Subsystem NT Executive NT Kernel Hardware Abstraction Layer Processor(s) Main Memory Devices Operating Systems: A Modern Perspective, Chapter 6

More Related