Windows – Object manager and process management - efreidoc.fr

Executive API / Executive Services. Cache. Manager .... a low level layer of the OS that manages much of the execution of ... and manage low level threads and.
1MB taille 0 téléchargements 39 vues
Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

Windows – Object manager and process management Mohammad S. Hasan Staffordshire University, UK

Windows – Object manager and process management

Slide 1

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

Lecture Outline Windows object management Threads and processes in Windows Thread priority and scheduling Thread synchronisation Inter-process communication Internal process and thread representation

Windows – Object manager and process management

Slide 2

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

Windows structure overview User Application Subsystem DLL

Environment Subsystem

System Support

System Services

NTdll.DLL User Mode Kernel Mode Executive API / Executive Services I/O Manager

File System

Cache Manager

Process and Thread Manager

Security Reference Monitor

Plug & Play Manager

Power Manager

Configuration Manager

Virtual Memory Manager

Object Manager / Local Procedure Call Device Drivers

Win32 User and GDI (Graphics Engine)

Graphics Drivers Kernel

Hardware Abstraction Layer (HAL)

Windows – Object manager and process management

Slide 3

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

System resources and data The OS needs to keep track of all the different resources Files I/O devices Memory

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

CPU usage

Windows – Object manager and process management

Slide 4

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 manipulates 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 manage the system resources and info about them Windows – Object manager and process management

Slide 5

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 6

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 7

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

Object Manager The function of the object manager is to provide services that manage all the objects in the system Various 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

Graphics Drivers Kernel

Hardware Abstraction Layer (HAL) Windows – Object manager and process management

Slide 8

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 9

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

Object Handles and Handle Table When 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 object Processes 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 10

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 11

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

Object structure Object Header

Object Body

Object name Object directory Security descriptor Quotas Open handle count Open handle list Object type

An object in the system has List of processes with handles to object

object header object body

Type Object

Object specific data

Windows – Object manager and process management

Slide 12

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 13

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

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) includes the code for all the methods that belong to the object class

Windows – Object manager and process management

Slide 14

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 it open - returns an object handle to calling process close - destroys handle delete - deletes object duplicate handle query information held in object

Windows – Object manager and process management

Slide 15

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

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, and one 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 16

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 17

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 18

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

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

Windows – Object manager and process management

Slide 19

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 20

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

The 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

Windows – Object manager and process management

Object Manager (High Level Object)

Kernel (Low Level Object)

Slide 21

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 22

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

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

Windows – Object manager and process management

Slide 23

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 24

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

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

Windows – Object manager and process management

Slide 25

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 created The kernel implements the dispatcher code, which determines which thread to run next The dispatcher implements pre-emptive scheduling among threads

Windows – Object manager and process management

Slide 26

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 27

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

Thread scheduling (Cont.) A ready thread is placed in the queue which represents its assigned priority There 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 28

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 event Or 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 29

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

Thread scheduling (Cont.) Real-time Priority threads Highest priority levels (16-31) Needing immediate responsiveness Static priorities

Dynamic Priority thread Lower priority levels (0-15)

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

Windows – Object manager and process management

Slide 30

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 31

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 32

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

Traps and exception handling Kernel implements a trap handler which deals with hardware interrupts and processor exceptions Divide by Zero Exception

Trap handler operation disables 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 33

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 behaviour These 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 34

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

Windows – Object manager and process management

Slide 35

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

Windows – Object manager and process management

Slide 36

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 37

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 list Thread information at the NT Executive level is held in an Executive Thread block (ETHREAD block)

Windows – Object manager and process management

Slide 38

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 39

Mohammad S. Hasan

Faculty of Computing, Engineering & Technology

References Operating System Concepts. Chapter 22.

Windows – Object manager and process management

Slide 40