Windows – Object manager and process managementyann.wankerdocs.free.fr/EFREI/L3/S5/Operating...

40
Mohammad S. Hasan Faculty of Computing, Engineering & Technology Windows – Object manager and process management Slide 1 Windows – Object manager and process management Mohammad S. Hasan Staffordshire University, UK

Transcript of Windows – Object manager and process managementyann.wankerdocs.free.fr/EFREI/L3/S5/Operating...

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Windows – Object manager and process management Slide 1

Windows – Object manager and process management

Mohammad S. HasanStaffordshire University, UK

Windows – Object manager and process management Slide 2

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Lecture Outline

Windows object managementThreads and processes in WindowsThread priority and schedulingThread synchronisationInter-process communicationInternal process and thread representation

Windows – Object manager and process management Slide 3

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Object Manager / Local Procedure Call

I/O Manager

User Mode

User Application

Subsystem DLL Environment Subsystem System Support System Services

NTdll.DLL

Kernel Mode

Executive API / Executive Services

Cache Manager

Process and Thread Manager

Security Reference

Monitor

Virtual Memory Manager

Win32 User and GDI

(Graphics Engine)Plug & Play

ManagerPower Manager Configuration

ManagerFile System

Device Drivers

Hardware Abstraction Layer (HAL)

Graphics Drivers

Kernel

Windows structure overview

Windows – Object manager and process management Slide 4

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

System resources and dataThe OS needs to keep track of all the different resources

FilesI/O devicesMemoryCPU usage

The OS keeps track of all processes (running programs)To do this the OS needs to keep info about these resources and their use.

Windows – Object manager and process management Slide 5

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

System resources and data (Cont.)In many OS the info is maintained in various data structures which the operating system code manipulatesIn Windows

the code that manipulates the data is kept together with the data in objects i.e. it uses an object oriented approach to manage the system resources and info about them

Windows – Object manager and process management Slide 6

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

System resources and data (Cont.)

ALL entities and services on the system are represented internally by objects e.g.

files are represented by objects,user programs when they are running on the computer, hardware resources like printers, communication ports, etc.

Motivation behind this is to provide a very modular structure which it is easy to update, extend, etc.

Windows – Object manager and process management Slide 7

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

System resources and data (Cont.)Abstraction i.e. hiding details of implementation of the object’s class

changes to internal implementation of an object's class can occur without affecting the code implementation of other object classes provided the interface remains unchanged

It also makes it easier to add new features and facilities to the system in the form of new object classes

Windows – Object manager and process management Slide 8

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Object ManagerThe function of the object manager is to provide services that manage all the objects in the systemVarious other components in the Windows Executive and the Environmental Subsystems can create, use, and destroy objects using Object Manager

Object Manager / Local Procedure Call

Device Drivers

Hardware Abstraction Layer (HAL)

Graphics Drivers

Kernel

Windows – Object manager and process management Slide 9

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Object manager (Cont.)Object manager provides a uniform set of services to the other components of the Executive - thus it simplifies object access

Windows – Object manager and process management Slide 10

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Object Handles and Handle TableWhen a process wants to use an object it calls the object manager to get a handle to that object handles are like pointers in C that allow you to access the methods and data of an objectProcesses must have an object handle for every resource/item that it uses e.g.

files, I/O devices, etc.

Windows – Object manager and process management Slide 11

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Object Handles and Handle Table (Cont.)

Each process has an Object Handle Table that contains all the handles to the various objects that the process has opened

Process

Windows – Object manager and process management Slide 12

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Object structureAn object in the system has

object headerobject body

Object nameObject directorySecurity descriptorQuotasOpen handle countOpen handle listObject type

Object specific data

ObjectHeader

ObjectBody

TypeObject

List of processeswith handlesto object

Windows – Object manager and process management Slide 13

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Object structure (Cont.)Object header contains information such as

the object's name, the hierarchy to which it belongs, security information (we will discuss that in more detail later), quota information, number of handles opened on object, pointer to a list of processes that have handles opened on object, pointer to an object that contains information about the object's type

Windows – Object manager and process management Slide 14

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Object structure (Cont.)

Object body contains information that is specific to the objectType object

contains information that is common to all objects of a particular type (class)includes the code for all the methods that belong to the object class

Windows – Object manager and process management Slide 15

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Object services

The object manager provides a set of services that are common to all objects:

create - creates object and returns a handle to itopen - returns an object handle to calling processclose - destroys handledelete - deletes objectduplicate handlequery information held in object

Windows – Object manager and process management Slide 16

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Processes and threadsIn Windows a process consists of

program code, execution context (the address space of the process plus such things as the access token), resources allocated to the process i.e. handles, andone or more threads

Threads are the units of execution – they execute program code using the processes context and resources

Windows – Object manager and process management Slide 17

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Processes and threads (Cont.)A thread has its own context i.e.

register values including instruction pointer, execution stack, and scheduling priority etc.

Threads are scheduled onto the processor, not a process.

this is different from Linux which for scheduling purposes treats threads as a separate process that happens to share address space with another thread

Windows – Object manager and process management Slide 18

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Processes and threads (Cont.)Processes and threads are managed by 2 components in Windows:

the process and thread manager the kernel

Windows – Object manager and process management Slide 19

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

The KernelThe kernel is responsible for:

Thread schedulingInterrupt and exception handlingLow level processor synchronisationRecovery after power failure

Windows – Object manager and process management Slide 20

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

The Kernel (Cont.)

In normal OS, the kernel refers to all the operating systems components that run in kernel mode.

In Windows, this applies to all the Windows Executive components (everything below the line in the diagram – slide 3).

However, Windows applies the name kernel to just one component –

a low level layer of the OS that manages much of the execution of threads within processes

Windows – Object manager and process management Slide 21

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

The Kernel (Cont.)The kernel uses objects to represent and manage low level threads and processesHowever these kernel objects are different from those managed by the Object ManagerThey are lower level and provide support for the higher level objects used by the Object Manager

Object Manager (High Level Object)

Kernel (Low Level Object)

Windows – Object manager and process management Slide 22

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Process and thread manager

Process manager is part of the Windows Executive.implements the representation of processes and threads that are available to other parts of the Executive and provides high level services to manage and control processes and threads

Windows – Object manager and process management Slide 23

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Process and thread manager (Cont.)

Process and thread manager provides functions toCreate and destroy processesControl resource allocation to processesKeep track of information about processes and threads

Processes are created by other processes by making a CreateProcess system call

Windows – Object manager and process management Slide 24

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Process and thread manager (Cont.)

Unlike Unix/Linux, the parent and child process are independent of each other.

remember fork in Unix/Linux creates the child as a copy of the parent and hence has a copy of the parents address space

In Windows child process has completely separate address space.Hence Windows does NOT keep track of process hierarchies

Windows – Object manager and process management Slide 25

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread schedulingWindows maintains a list of threads that are in the systemThreads may be in one of several different states

Ready – thread can execute but waiting for a processor Running – running on a processorStandby - selected to run next on a processorWaiting – unable to execute until some event occurs (typically I/O)Terminated

Windows – Object manager and process management Slide 26

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread scheduling (Cont.)All processes have at least one thread known as the base thread – created when the process is createdThe kernel implements the dispatcher code, which determines which thread to run nextThe dispatcher implements pre-emptive scheduling among threads

Windows – Object manager and process management Slide 27

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread scheduling (Cont.)

The dispatcher schedules threads without reference to the process they belong to.

hence a process that has more threads will if everything else is equal have a greater share of the processor

The scheduling algorithm is based on a multilevel priority queue approach with each thread having a priority and hence belonging to a given queue

Windows – Object manager and process management Slide 28

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread scheduling (Cont.)A ready thread is placed in the queue which represents its assigned priorityThere are 32 priority queue levels

highest priority – 31 lowest priority - 0

Dispatcher starts with highest priority queue and schedules threads in order in queue in round robin fashion

Windows – Object manager and process management Slide 29

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread scheduling (Cont.)

Each thread is given a time quantum to execute it either blocks itself waiting on some I/O or synchronisation eventOr the quantum expires

Once the current queue is empty, the dispatcher proceeds to the next lowest priority queue and so on

until the queues are all empty or a higher level priority thread enters a ready state and dispatcher pre-empts lower priority running thread

Windows – Object manager and process management Slide 30

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread scheduling (Cont.)

Real-time Priority threadsHighest priority levels (16-31)Needing immediate responsivenessStatic priorities

Dynamic Priority threadLower priority levels (0-15)

A processes base thread is given a base prioritythe minimum priority thread in that process

Windows – Object manager and process management Slide 31

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread scheduling (Cont.)

Each process has:a base priority class (which defines a range of priority levels which the base priority can take on) and a base priority level which specifies the actual base priority a thread should have in the base priority class for a given process

Windows – Object manager and process management Slide 32

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread scheduling (Cont.)

Each thread then takes on priority values dynamically i.e. it changes over time

e.g. if the thread is delayed waiting on an I/O event, when the I/O event occurs and the thread becomes ready again, its priority is increased temporarily. The size of the increase depends on the length of the wait – the longer the wait the greater the increase in priority

Windows – Object manager and process management Slide 33

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Traps and exception handlingKernel implements a trap handlerwhich deals with hardware interrupts and processor exceptions

Divide by Zero Exception

Trap handler operationdisables interrupts, determines the cause of the interrupt, saves processor state, re-enables interrupts and dispatches interrupt service routine to handle it

Windows – Object manager and process management Slide 34

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread synchronisation

Windows provides a set of dispatcher objects which can be used for synchronisation of thread behaviourThese dispatcher objects can be

In a signalled state (when the event that the thread is waiting for occurs) or In a unsignaled state (when the event has not yet occurred)

Windows – Object manager and process management Slide 35

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Thread synchronisation (Cont.)Event objects represent events such as I/O events – when the relevant event occurs the object manager sets the event object to the signalled stateMutex objects provide mutual exclusion – only one thread can have a mutex object – it does this by setting the object into an unsignaled state. Once the thread completes its activity it sets the mutexobject to the signalled stateWaitable timer objects – these objects remain unsignaled until a given time has elapsed

Windows – Object manager and process management Slide 36

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Inter-process communication

Threads (and hence also processes) can communicate using a variety of methods

Pipes – work very similar to Unix – unidirectional communication via a shared bufferSockets – similar to pipes but usually connect processes and threads on different machinesRemote procedure calls – allows a thread in one process to invoke the execution of code in different processes address spaceFile sharing is also implemented

Windows – Object manager and process management Slide 37

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Internal process and thread representation

Processes are represented within the NT Executive by a process control block (Executive Process Control or EPROCESS block).It stores information that other executive components use when manipulating a process

process id, pointer to processes handle table, pointer to processes access token (used to determine security in access) etc.

Windows – Object manager and process management Slide 38

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Internal process and thread representation (Cont.)

Also contains a pointer to a kernel level process block (KPROCESS block). This contains information when used in scheduling a process, such as priority, time quantum to be used, etc.EPROCESS blocks are held in a linked listThread information at the NT Executive level is held in an Executive Thread block (ETHREAD block)

Windows – Object manager and process management Slide 39

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

Internal process and thread representation (Cont.)

As with processes the ETHREAD block includes a pointer to a kernel level kernel thread block (KTHREAD block)

Windows – Object manager and process management Slide 40

Mohammad S. Hasan Faculty of Computing, Engineering & Technology

References

Operating System Concepts. Chapter 22.