C06 Operating System With Unix Vtu

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 26

Process Management

External View of the OS


wait()
close()
sleep()
File Mgr
fork()
signal()
Device Mgr
semctl()
C Hardware
Program Memory Mgr
SetWaitableTimer()
CreateProcess() Process Mgr
CreateThread()
CloseHandle()
OS
WaitForSingleObject()
Process Management 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)
Initializing the Machine
• Power up  fetch-execute cycle begins
• Initial (or hardware) process begins to run
• Executes ROM diagnostic program
• Then bootstrap loads the OS
• OS initialization
– Setup & initialize all system data structures (this
creates process & resource abstractions)
– Initialize all devices
– Start daemons – including idle process
– Branches to the scheduler
Hardware Process Starts

Idle Process Kernel ISRs Process i Process j


BIOS

Program

Hardware
process

Switch to
another
program
Process Mgr
Process Abstraction Layers
pi, pj, and pk each
Pi Pj Pk
have their own
Virt Term Virt Term Virt Term
virtual terminal
Window Mgr interface

Pi Pj Pk pi, pj, and pk each


Control Control Control have their own
Unit Unit Unit virtual machine
OS interface
OS Pi
Address Address Hardware process
Space Space (OS) coroutines across
pi, pj, and pk under OS
Pk
Control Address control
Pj
Unit Address
Space
Space
Process Mgr

Process Manager Overview


Program Process

Abstract Computing Environment

File Deadlock Process


Manager Protection Description

Synchronization
Device Memory Resource
Manager Manager Scheduler Resource
Resource
Manager
Manager
Manager

Devices Memory CPU Other H/W


Unix Organization
Process Process
Libraries
Process

System Call Interface


File Deadlock Process
Manager Protection Description

Synchronization
Device Memory Resource
Manager Manager Scheduler Resource
Resource
Manager
Manager
Monolithic Kernel Manager

Devices Memory CPU Other H/W


NT Organization
Process T Process
T T
T T T
T T Process
T
Libraries
Subsystem Subsystem Subsystem
User
Supervisor
NT Executive
NT Kernel I/O Subsystem
Hardware Abstraction Layer

Processor(s) Main Memory Devices


Process Descriptor
• 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)
Creating a Process in UNIX
pid = fork();

UNIX kernel

Process Table


Process Descriptor
Creating a Process in NT
CreateProcess(…);

Win32 Subsystem

ntCreateProcess(…);

ntCreateThread(…);

NT Executive

Handle Table

NT Kernel

Process Descriptor
Handles

Application
Handle
User Space
Supervisor Space

Executive Object
NT Executive
Kernel
Object

NT Kernel
NT Process Descriptor

User Space
Supervisor Space
NT Executive

EPROCESS ETHREAD

NT Kernel
KPROCESS
(PCB)

KTHREAD
NT Process Descriptor
 Kernel process object including:
 Pointer to the page directory
 Kernel & user time
 Process base priority
 Process state
 List of the Kernel thread descriptors that are
using this process
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
Resource Model
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 |  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.
Using the Model
• 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
•pi can release units of Rj that it holds (reusable) or
produces (consumable)
request Mgr(Rj)

allocate
release

Process
Resource Manager Design

Mgr(Rj)
request release

allocate
release
allocate

release
Process
allocate
Resource Pool
Address Space

Primary
Memory

Address Space
Process Mailboxes
Files

System services

Other objects
Defining 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
The Compile Time Component
Source
Modules

Translator Relocatable
Modules

Link Editor Absolute Primary Memory


Program

Loader Executable
Program
Address Space

Map
Map
State

Resources
State

Static data Stack


Processes &Threads

Program Stack
Process State (Version 1)
Request
Done
Running

Request Schedule

Allocate Start

Blocked Ready
Process State (UNIX)
Request
Wait by
parent Done
Running
zombie Schedule
Request
Sleeping I/O Request
Allocate
Start

Runnable
I/O Complete Resume

Uninterruptible Traced or Stopped


Sleep
Process Hierarchies
• Parent-child relationship may be significant:
parent controls children’s execution
Request
Done
Running
Yield Suspend
Request Schedule
Suspend Start
Ready-Active
Activate Ready-Suspended
Allocate Allocate
Suspend
Blocked-Active Blocked-Suspended
Activate

You might also like