Implementing Processes, Threads, and Resources
Download
Report
Transcript Implementing Processes, Threads, and Resources
Slide 6-1
Implementing
Processes, Threads,
and Resources
Copyright © 2004 Pearson Education, Inc.
6
Operating Systems: A Modern Perspective, Chapter 6
Implementing the Process Abstraction
Pi CPU
Pj CPU
Pi Executable
Memory
Pj Executable
Memory
Pk CPU
…
Pk Executable
Memory
OS Address
Space
CPU
ALU
Control
Unit
Pi Address
Space
Pk Address
Space
…
Pj Address
Space
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 6
Machine Executable Memory
OS interface
Slide 6-2
Process Manager Responsibilities
Slide 6-3
• 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)
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 6
Slide 6-4
Processes &Threads
Stack
State
Copyright © 2004 Pearson Education, Inc.
Static data
Map
Operating Systems: A Modern Perspective, Chapter 6
Program
Map
Resources
Address Space
Stack
State
Slide 6-5
The Address Space
Address
Space
Address
Binding
Executable
Memory
Process
Files
Other objects
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
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 6
Slide 6-6
The Abstract Machine Interface
Slide 6-7
Application Program
Abstract Machine Instructions
Trap
Instruction
User Mode
Instructions
fork()
open()
OS
User Mode
Instructions
Copyright © 2004 Pearson Education, Inc.
Supervisor Mode
Instructions
Operating Systems: A Modern Perspective, Chapter 6
create()
Slide 6-8
Context Switching
Executable Memory
Initialization
Interrupt
1
Process
Manager
7
8
Interrupt
Handler
2
4
3
P1
9
5
P2
6
Pn
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
etc. (see Table 6.1 and the source code of your
favorite OS)
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 6
Slide 6-9
Creating a Process in UNIX
pid = fork();
UNIX kernel
Process Table
…
Copyright © 2004 Pearson Education, Inc.
Process Descriptor
Operating Systems: A Modern Perspective, Chapter 6
Slide 6-10
Slide 6-11
Simple State Diagram
Request
Done
Running
Request
Schedule
Start
Allocate
Blocked
Copyright © 2004 Pearson Education, Inc.
Ready
Operating Systems: A Modern Perspective, Chapter 6
UNIX State Transition Diagram
Request
Wait by
parent
Done
Running
zombie
Sleeping
Schedule
Request
I/O Request
Start
Allocate
Runnable
I/O Complete
Uninterruptible
Sleep
Copyright © 2004 Pearson Education, Inc.
Resume
Traced or Stopped
Operating Systems: A Modern Perspective, Chapter 6
Slide 6-12
Resources
Resource: Anything that a process can request, then be
blocked because that thing is not available.
R = {Rj | 0 j < m} = resource types
C = {cj 0 | RjR (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.
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 6
Slide 6-13
Using the Model
Slide 6-14
• There is a resource manager, Mgr(Rj) for every Rj
• 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
Mgr(Rj)
Process
allocate
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 6
A Generic Resource Manager
Resource Manager
Policy
Blocked Processes
ProcessProcess
Process
request()
Process
release()
Resource Pool
Copyright © 2004 Pearson Education, Inc.
Operating Systems: A Modern Perspective, Chapter 6
Slide 6-15