CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

42
CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management

Transcript of CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Page 1: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

CE01000-3 Operating Systems

Lecture 11Windows – Object manager and

process management

Page 2: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Overview of lecture

In this lecture we will be looking at: Windows object management Threads and processes in Windows Thread priority and scheduling Thread synchronisation Interprocess communication Internal process and thread representation

Page 3: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Windows structure overview

USER APPLICATION SYSTEM SYSTEM SUBSYSTEM DLL ENVIRONMENT SUBSYSTEM SUPPORT SERVICES

NTDLL.DLL USER MODE

KERNEL MODE EXECUTIVE

API

I/O MANAGER

CACHE MANAGER

PROCESS & THREAD MANAGER

SECURITY REFERENCE MONITOR

VIRTUAL MEMORY MANAGER

Win32 USER and GDI (Graphics engine)

FILE SYSTEMS

PLUG & PLAY MANAGER

POWER MANAGER

CONFIGUARION MANAGER??

OBJECT MANAGER /

LOCAL PROCEDURE CALL

Graphics drivers

DEVICE

DRIVERS KERNEL

HARDWARE ABSTRACTION LAYER (HAL)

Page 4: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

System resources and data In any operating system the system needs to keep

track of all the different resources that exist in the system e.g. files, I/O devices, memory, system processes

It needs to keep track of all the various processes (running programs) that use those resources

To do this it needs to keep information about these resources and their use.

Page 5: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

System resources and data (Cont.)

In many operating systems the information is maintained in various data structures which the operating system code manipulates

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

Page 6: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

System resources and data (Cont.)

ALL entities and services on the system are represented internally by objects e.g. files are represented by objects, as are 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.

Page 7: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

System resources and data (Cont.) By hiding details of implementation of each

object’s class, changes to internal implementation of an object's class can occur without impacting upon the code implementation of other object classes in the system 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

Page 8: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Object manager The function of the object manager is to

provide services that manage all the objects in the system

It provides mechanisms by which the various other components in the Windows Executive and the environmental subsystems can create, use, and destroy objects

Page 9: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Object manager (Cont.) Object manager provides a uniform set of

services to the other components of the Executive - thus it simplifies object access, etc, because the same mechanism is used in each case

Page 10: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Object Handles and Handle Table When a process (running program) wants to

use an object it calls the object manager open service to get a handle to that object

handles are like pointers in C that allow you to access the methods and data of an object

Processes must have an object handle for every resource/item that it uses e.g. files, I/O devices, etc.

Page 11: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

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

Page 12: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Object Handles and Handle Table (Cont.)

Process

......

O bject H andle T ab le O b jects

Page 13: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Object structureO bject n am eO bject d irectoryS ecu rity d escrip torQ u otasO pen h an d le cou n tO pen h an d le listO bject type

O bject specific d ata

O bjectH ead er

O bjectB od y

T ypeO bject

L ist of processesw ith h an d lesto object

Page 14: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Object structure (Cont.) Objects in the system have object headers and

object bodies 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

Page 15: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Object structure (Cont.) Object body contains information that is

specific to the object Type object contains information that is

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

Page 16: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Object services The object manager provides a set of services

that are common to all objects: create - creates object and returns a handle to it open - returns an object handle to calling process close - destroys handle delete - deletes object duplicate handle query information held in object

Page 17: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Processes and threads

In 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, one or more threads

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

Page 18: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Processes and threads (Cont.)

A thread has its own context (register values including instruction pointer, execution stack, and such things as scheduling priority)

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 [Note – change to handout]

Page 19: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Processes and threads (Cont.)

Processes and threads are managed by 2 components in Windows:

the process and thread manager

and the kernel

Page 20: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

kernel

The kernel is responsible for: Thread scheduling Interrupt and exception handling Low level processor synchronisation Recovery after power failure

Page 21: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

kernel (Cont.) In normal Operating Systems the kernel refers to

all the operating systems components that run in kernel mode. In Windows as we have seen this applies to all the Windows Executive components (everything below the line in the diagram).

However, perversely, 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

Page 22: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

kernel (Cont.)

The kernel uses objects to represent and manage low level threads and processes

However these kernel objects are different from those managed by the Object Manager

They are lower level and provide support for the higher level objects used by the Object Manager

Page 23: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Process and thread manager

Process manager is part of the Windows Executive and 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

Page 24: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Process and thread manager (Cont.)

Process and thread manager provides functions to Create and destroy processes Control resource allocation to processes Keep track of information about processes and

threads Processes are created by other processes by

making a CreateProcess system call

Page 25: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

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, etc.

Hence Windows does not keep track of process hierarchies

Page 26: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Thread scheduling Windows maintains a list of threads that are in the

system Threads may be in one of several different states

Ready – thread can execute but waiting for a processor Running – running on a processor Standby - selected to run next on a processor Waiting – unable to execute until some event occurs

(typically I/O) Terminated

Page 27: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Thread scheduling (Cont.)

All processes have at least one thread known as the base thread – created when the process is created

Page 28: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Thread scheduling (Cont.)

The kernel implements the dispatcher code, which determines which thread to run next

The dispatcher implements pre-emptive scheduling among threads

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

Page 29: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Thread scheduling (Cont.)

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

A ready thread is placed in the queue which represents its assigned priority

There are 32 priority queue levels designated by numbers with 31 highest priority and 0 lowest

Page 30: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Thread scheduling (Cont.) Dispatcher starts with highest priority queue

and schedules threads in order in queue in round robin fashion

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

Page 31: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Thread scheduling (Cont.) Once a given queue is empty, the dispatcher

then 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 i.e. one of the higher level queues is now no longer empty – and dispatcher pre-empts lower priority running thread

Page 32: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Thread scheduling (Cont.)

Highest priority levels (16-31) is for real-time threads (needing immediate responsiveness) – the real-time priorities are static

Lower priority levels (0-15) are for dynamic priority threads

A processes base thread is given a base priority – which is the minimum priority a thread can have

Page 33: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Thread scheduling (Cont.)

Each process has: a base priority class (a range of priority

levels which the define the possible range of base priorities) and

a base priority level which specifies the relative base priority a threads should have in the base priority class

Page 34: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

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

Page 35: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Traps and exception handling

Kernel implements a trap handler which deals with hardware interrupts and processor exceptions

The trap handler disables interrupts, determines the cause of the interrupt, saves processor state, re-enables interrupts and dispatches code to deal with type of interrupt/exception found (Interrupt service routine)

Page 36: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Thread synchronisation

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

These dispatcher objects can be in a signalled state (when the event that the thread is waiting for occurs) or a unsignaled state (when the event has not yet occurred)

Page 37: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

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 state

Mutex 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 mutex object to the signalled state

Waitable timer objects – these objects remain unsignaled until a given time has elapsed

Page 38: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Interprocess communication

Threads (and hence also processes) can communicate using a variety of methods Pipes – work very similar to Unix – unidirectional

communication via a shared buffer Sockets – similar to pipes but usually connect

processes and threads on different machines Remote procedure calls – allows a thread in one

process to invoke the execution of code in different processes address space

File sharing is also implemented

Page 39: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

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.

Page 40: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

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 list Thread information at the NT Executive level is

held in an Executive Thread block (ETHREAD block)

Page 41: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

Internal process and thread representation (Cont.)

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

Page 42: CE01000-3 Operating Systems Lecture 11 Windows – Object manager and process management.

References Operating System Concepts. Chapter 22.