process management. external view of the os hardware fork() createprocess() createthread() close()...

26
Process Management

Post on 21-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Process Management

External View of the OS

Hardware

fork()

CreateProcess()

CreateThread()

close()

CloseHandle()

sleep()

semctl()signal()

SetWaitableTimer()

wait()

WaitForSingleObject()

CProgram

CProgram

OSProcess Mgr

Memory Mgr

Device Mgr

File Mgr

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

Kernel Process jProcess iISRsIdle Process

Hardware Process Starts

Program

Hardwareprocess

Switch toanotherprogram

BIOS

Process Abstraction Layers

ControlUnit

Pi

AddressSpace

Pi

AddressSpace

Pj

AddressSpace

Pj

AddressSpace

Pk

AddressSpace

Pk

AddressSpace

Hardware process (OS) coroutines across pi, pj, and pk under OS control

Pi

ControlUnit

Pj

ControlUnit

Pk

ControlUnit

pi, pj, and pk each have their own virtual machine

OS interface

Pi

Virt TermPj

Virt TermPk

Virt Term

pi, pj, and pk each have their own virtual terminal

Window Mgr interface

OSAddressSpace

OSAddressSpace

Process Mgr

Process Manager Overview

ProgramProgram ProcessProcess

Abstract Computing Environment

FileManager

MemoryManager

DeviceManager

ProtectionProtectionDeadlockDeadlock

SynchronizationSynchronization

ProcessDescription

ProcessDescription

CPUCPU Other H/WOther H/W

SchedulerScheduler ResourceManager

ResourceManagerResource

Manager

ResourceManagerResource

Manager

ResourceManager

MemoryMemoryDevicesDevices

Process Mgr

System Call InterfaceSystem Call Interface

Unix Organization

FileManager

MemoryManager

DeviceManager

ProtectionProtectionDeadlockDeadlock

SynchronizationSynchronization

ProcessDescription

ProcessDescription

CPUCPU Other H/WOther H/W

SchedulerScheduler ResourceManager

ResourceManagerResource

Manager

ResourceManagerResource

Manager

ResourceManager

MemoryMemoryDevicesDevices

LibrariesLibraries ProcessProcess

ProcessProcess

ProcessProcess

Monolithic Kernel

NT Organization

Processor(s) Main Memory Devices

LibrariesLibraries

ProcessProcess

ProcessProcess

ProcessProcess

SubsystemSubsystemUser

Supervisor

SubsystemSubsystem SubsystemSubsystem

Hardware Abstraction LayerHardware Abstraction LayerNT Kernel

NT ExecutiveI/O SubsystemI/O Subsystem

TT

TT

TT T T

T

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 kernelUNIX kernel

Process Table

Process Descriptor

Creating a Process in NTCreateProcess(…);

Win32 SubsystemWin32 Subsystem

ntCreateProcess(…);…ntCreateThread(…);

NT ExecutiveNT Executive

NT KernelNT Kernel…

Handle Table

Process Descriptor

Handles

Application

KernelObject

Executive Object

User Space

Supervisor Space

NT Executive

NT Kernel

Handle

NT Process Descriptor

KPROCESS(PCB)

EPROCESS

User Space

Supervisor Space

ETHREAD

KTHREAD

NT Kernel

NT Executive

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

R = {Rj | 0 j < m} = resource typesC = {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.

Resource: Anything that a process can request, then be blocked because that thing is not available.

Using the Model• There is a resource manager, Mgr(Rj) for every Rj

Mgr(Rj)

pi can only request ni cj units of reusable Rj

pi can request unbounded # of units of consumable Rj

• Process pi can request units of Rj if it is currently running

ProcessProcess

request

•Mgr(Rj) can allocate units of Rj to pi

allocate

release

•pi can release units of Rj that it holds (reusable) or produces (consumable)

Resource Manager Design

Mgr(Rj)

ProcessProcess

Resource Pool

releaserequest

allocate

allocate

allo

cate

release

rele

ase

Address Space

ProcessProcess

Add

ress

Spa

ce

PrimaryMemory

PrimaryMemory

Mailboxes

System services

Other objects

Files

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

SourceModules

TranslatorTranslator RelocatableModules

Link EditorLink Editor AbsoluteProgram

LoaderLoader ExecutableProgram

Primary Memory

Processes &Threads

Add

ress

Spa

ceA

ddre

ss S

pace

MapMap

Sta

ck

State

Pro

gram

Sta

tic d

ata

Res

ourc

es

Sta

ck

State

MapMap

Process State (Version 1)

ReadyBlocked

Running

Start

Schedule

Request

Done

Request

Allocate

Process State (UNIX)

Runnable

UninterruptibleSleep

Running

Start

Schedule

Request

Done

I/O Request

Allocate

zombie

Wait byparent

Sleeping

Traced or Stopped

Request

I/O Complete Resume

Process Hierarchies• Parent-child relationship may be significant:

parent controls children’s execution

Ready-Active

Blocked-Active

Running

StartSchedule

RequestDone

Request

AllocateReady-Suspended

Blocked-Suspended

SuspendYield

AllocateSuspend

Suspend

Activate

Activate