Outline • Process Management – Process manager – Hardware process

advertisement
Outline
• Process Management
– Process manager
– Hardware process
– Process abstraction
• Process descriptor
– Thread abstraction
Basic OS Functions
5/29/2016
COP4610
2
Process Manager
• Process manager creates the process abstraction
– It implements a software environment for processes
to run
• Algorithms that define the behavior of the operating
system
• Data structures to preserve the state of the execution
5/29/2016
COP4610
3
Process Manager – cont.
• Process manager consists of
– Basic algorithms and data structures to
implement the process and resource abstractions
– Managing resources used by processes/threads
– Tools to create/destroy/manipulate processes and
threads
– Scheduling
– Process synchronization
– A deadlock strategy
– Protection strategy
5/29/2016
COP4610
4
Process Manager – cont.
Program
Process
Abstract Computing Environment
File
Manager
Deadlock Process
Description
Protection
Synchronization
Device Memory
Manager Manager
Devices
5/29/2016
Scheduler
Memory
CPU
COP4610
Resource
Resource
Resource
Manager
Manager
Manager
Other H/W
5
Implementing the Process Abstraction
Pi CPU
Pj CPU
Pi Executable
Memory
Pj Executable
Memory
Pk CPU
…
Pk Executable
Memory
OS Address
Space
Pi Address
Space
CPU
ALU
Pk Address
Space
…
Control
Unit
Pj Address
Space
5/29/2016
COP4610
Machine Executable Memory
OS interface
6
External View of the Process Manager
Application
Program
Device Mgr
UNIX
Memory Mgr
File Mgr
exec()
Memory Mgr
File Mgr
Process Mgr
Device Mgr
wait()
CreateThread()
CloseHandle() CreateProcess()
WaitForSingleObject()
Process Mgr
fork()
Windows
Hardware
5/29/2016
COP4610
7
Modern Processes and Threads
Thrdj in Pi
Thrdk in Pi
…
Pi CPU
…
…
OS interface
…
5/29/2016
COP4610
8
Modern Processes and Threads – cont.
5/29/2016
COP4610
9
Processes
• A process is a sequential program in
execution
–
–
–
–
The object program to be executed
The data on which the program will execute
Resources required by the program
The threads in the process
• A host process environment
• The status of each thread’s execution
– Thread-specific data, such as a stack, a PC, and set of
register values
5/29/2016
COP4610
10
Process Address Space
• Process address space
– A set of locations used by a process to reference
primary memory locations, OS services, and
resources
5/29/2016
COP4610
11
The Address Space
Address
Space
Address
Binding
Executable
Memory
Process
Files
Other objects
5/29/2016
COP4610
12
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
5/29/2016
COP4610
13
Process Address Space – cont.
5/29/2016
COP4610
14
System Overview
5/29/2016
COP4610
15
Instruction Execution
• Instruction fetch (IF)
MAR  PC; IR  M[MAR]
• Instruction Decode (ID)
A  Rs1; B  Rs2; PC  PC + 4
• Execution (EXE)
– Depends on the instruction
• Memory Access (MEM)
– Depends on the instruction
• Write-back (WB)
5/29/2016
COP4610
16
The Hardware Process
• Hardware process refers to the iterative
activity of the control unit
– It fetches an instruction and then executes it
repeatedly
5/29/2016
COP4610
17
Tracing the Hardware Process
Hardware process progress
Machine is
Powered up
Bootstrap
Process Interrupt
Loader Manager Handler P1
Load the kernel
Initialization
Execute a thread
Schedule
P,2
Pn
…
Service an interrupt
5/29/2016
COP4610
18
Context Switching
Old Thread
Descriptor
CPU
New Thread Descriptor
5/29/2016
COP4610
19
Context Switching – cont.
Executable Memory
Initialization
Interrupt
1
Process
Manager
7
8
Interrupt
Handler
2
4
9
3
P1
P2
5
6
Pn
5/29/2016
COP4610
20
The Abstract Machine Interface
Application Program
Abstract Machine Instructions
Trap
Instruction
User Mode
Instructions
fork()
open()
create()
OS
User Mode
Instructions
5/29/2016
Supervisor Mode
Instructions
COP4610
21
Process Descriptors
• OS creates/manages process abstraction
• Descriptor is data structure for each process
–
–
–
–
–
5/29/2016
Type & location of resources it holds
List of resources it needs
List of threads
List of child processes
Security keys
COP4610
22
Process Descriptor – cont.
5/29/2016
COP4610
23
Windows NT Process Descriptor
EPROCESS
KPROCESS
NT Kernel
NT Executive
5/29/2016
…
uint32
uint32
…
Byte
…
void
…
COP4610
KernelTime;
UserTime;
state;
*UniqueProcessId;
24
Windows NT Process Descriptor – cont.
 Kernel process object including:





5/29/2016
Pointer to the page directory
Kernel & user time
Process base priority
Process state
List of the Kernel thread descriptors that are
using this process
COP4610
25
Windows NT Process Descriptor – cont.









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
5/29/2016
COP4610
26
Thread Abstraction
• The major tasks in managing a thread include
– Create/destroy a thread
– Allocate thread-specific resources
– Manage thread context switching
• The thread descriptor is the data structure
where the OS keeps all information to
manage that thread
5/29/2016
COP4610
27
Thread Abstraction – cont.
5/29/2016
COP4610
28
Windows NT Thread Descriptor
EPROCESS
KPROCESS
ETHREAD
KTHREAD
NT Kernel
NT Executive
5/29/2016
COP4610
29
Simple State Diagram
Request
Done
Running
Request
Schedule
Start
Allocate
Ready
Blocked
5/29/2016
COP4610
30
UNIX State Transition Diagram
Request
Wait by
parent
zombie
Sleeping
Done
Running
Schedule
Request
I/O Request
Start
Allocate
Runnable
I/O Complete
Traced or Stopped
Uninterruptible
Sleep
5/29/2016
Resume
COP4610
31
Windows NT Thread States
CreateThread
Initialized
Reinitialize
Activate
Exit
Wait
Running
Waiting
Ready
Wait Complete
Wait Complete
Transition
Preempt
Dispatch
Select
Terminated
Dispatch
Standby
5/29/2016
COP4610
32
Summary
• Process manager
– It creates abstract machines for process to run in
– It is achieved by time-multiplexing the hardware
through context-switching
– To manage processes / threads, process manager
uses data structures (process descriptor and
thread descriptor) to keep the information for
manipulating them
5/29/2016
COP4610
33
Session Information
• COP 4610 / CGS 5765
–
–
–
–
–
Section
Section 6
Section 2
Section 3
Section 4
5/29/2016
Recitation time
08:00-08:55 AM
09:05-09:55 AM
11:15AM -12:05 PM
12:20-1:10 PM
COP4610
34
Download