Os Intro11 Class

  • Upload
    prakash

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

  • 8/12/2019 Os Intro11 Class

    1/33

  • 8/12/2019 Os Intro11 Class

    2/33

    physical address mapping - this is useful in memory protection

    in processes %%% - performance issues related to 0 in embedded and real time systems %%%

    - loading applications/processes larger than physical memory sie of the system %%

    - you may fine tune the physical memoryand swap space of a given computing system

    as per the applications reuirement %%%

    - s/w components that provide interface betweenuser and computing system %%%- '"/* interfaces

    - system libraries - programming is involved %% - system utilities/tools %%% - tas utilities - to control/terminate

    certain applications in the system %%% - as a developer - managing own

    processes/threads %%% - file system defragmenter/repairing %%% - system parameters tuning using

    special utilities %%% - operating system parameters can

    be tuned as per reuirements ofthe administrator or developer %%%

    - in "inu+2 you will be dealing withprocfs and sysfs interfaces %%%

    - as we progress and do more practicals2 serveral utilities will be used - you may

    learn one after another %%% - these system utilities invariably use system libraries and interact with

    core system components %%%- system libraries typically provide

    system call !,s %%% these !,s provide access to core services of operating system %%% this is one way of interacting with O3 %%% - system s/w components mae up the core and non-core parts of the operating system - core components are mainly responsible for initialiing and

    managing the h/w/logical/virtual resources and

    providing services to non-core components2 applications and users - non core components are libraries2 utilities/tools and e+ecution framewors that enable

  • 8/12/2019 Os Intro11 Class

    3/33

    the users/developers/administrators to interface and utilitie the core services of operating system %%

    - core components may be more priviliged than non core components %%%(privilige or less privilige

    is decided by hw platform via appropriate setup)

    - what does it mean by more priviliged2 here &&& - most core components can interact with h/w resources/controllers2 directly %%% - core components may have access to

    all parts of the systems physical memory %%% - certain core components(certain

    system processes) may be given higher priority and accordingly more cpu time/importance %%

    - core components can directly interactand allocate memory from the physicalmemory manager %%%

    - core components are very essential for thecomputing system and non core components and

    applications may not be able to function withoutthe former %%%

    4. operating system also provides an environment in which developers can develop and build/test applications

    - software development its2 if any %%%- you will learn more when you wor in the lab %%%

    - in your case2 ernel will provide a specialdevelopment env2 for system space coding andloading %%% non-5!' students %%

    6. operating system also provides a controlled environment in whichapplications can be loaded and e+ecuted

    - scheduling several active applications2 in a multitasingenvironment %%processes are typically used %%%

    - support inter process communication /networing- manage server processes / server daemons/ernel threads %%%

    - virtual memory environment %%%you may or may not use this feature/mechanism%%

    - depending upon application sie2 we may or may not use it %%% - it also depends on deterministic behaviour( reuirements) and

    acceptance of non deterministic behaviour(reuirements)%%

    - why vm is popular in ,O3 systems &&& - efficient multitasing and efficient usage of

    physical memory %%%

  • 8/12/2019 Os Intro11 Class

    4/33

    - operating system manages multiprocessor2 multitasing %%% - why multiprocessing &&& - to increase throughput and increased

    responsiveness %%% we will see more during threading %%%

    Note 7 what happens if the underlying os does not support , or computing system does not support operating system &&& - only one processor may be utilied for

    applications e+ecution and other processors will remain idle %%% this means2 much lower throughput and poor response times %%%% - 5835 / 50835 will use this during

    R9O3/8O3- 5!33 will use this during R9O3

    - 5335 will use it for parallel programming/ threading %%%%- several cpu resources are needed to implementdeterministic/responsive scheduling for severalprocesses/tass %%%(understood betterduring R9O3)

    - depending upon your reuirement2 you will comeacross appropriate os services %%%

    (analogous to registers of microcontrollers2 once the underlying arch. is understood)

    - in certain cases2 os will provide certainservices without intervention of thedeveloper(implicit)

    - in certain cases2 os will be provide certainservices to be used by the developer(framewor)2 as needed %%% how does a operatingprovide services to the developer &&&

    - mostly via system call !,s %%% - in certain cases2 services are offered

    via system utilities %%% - in certain cases2 you will be dealing with

    system !,s2not system call !,s %%% - system call !,s are for user-space access and

    system !,s are for system space access %% - processor e+ception handling - fatal error handling

    - applications or system sw components areterminated by handling e+ecptions withstrict rules - this enables developers

    and users to rectify and fi+ the bugs %%% - applications may crash for various reasons- one could be a fatal e+ception - another

  • 8/12/2019 Os Intro11 Class

    5/33

    could be lac of resources or something else - what is the understanding of application crash2 in this conte+t && - application is abnormally terminated by the operating system %%%

    - who is responsible for crashingthe application &&

    - operating system - cpu may beinvolved in generating e+ceptions %%%

    - details will be discussed duringe+ceptions/e+ception handling %%

    - how is the crashing achieved &&& - forced termination by operating system

    - what is the meaning of fatal e+ception

    in this conte+t &&& - this depends on how the processortreats the illegal action of aapplication %%% some very goode+amples can be seen during memory

    management %%% - how is the e+ception of the processor connected to the underlying operating

    system && which subsystem is responsible for such a connection && you are e+pected to find the answer &&& - give a scenario for lac of resources and crashing of the application &&& - this is typically not an e+ception %%% - in a virtual memory system2 when virtual memory resources are

    e+hausted and certain processesare still demanding for memory2operating system may terminate

    one or more such processes %%%

    - not all types of application crashes arepossible in all computing environments -certain computing environments may beusing robust techniues such that most

    of such crashes/abnormal terminations areeliminated %%% ultimately2 it depends on the

    e+ecution environment provided by the O3 (R9O3) and developers sills %%% - the e+ecution environment may be fine

  • 8/12/2019 Os Intro11 Class

    6/33

    tuned as per the reuirements of thecomputing system/applications %%-

    - the above are true in the case ofany O3 - degree of controlvaries %%%

    - it is also the responsibility of the operatingsystem to generate its own crash2 if certaincore component misbehaves - this is a built inintelligence %%% the intelligence is implemented

    in the form of code 2 which includes a detailed set of rules %%% - why do operating systems crash && - unable to load a critical module/component of the

    core of the O3 %%%unable to detect /initialie acritical hw component in the system %%%

    - you will come across during system space codeing &&- what is a crash &&

    - who is responsible forgenerating a crash &&&

    - core components will have chec points in their code and they generate the crashes2 if a chec

    fails %% - you may have to debug the crash messages - which will reuire a thorough understanding of one or more subsystems %%%

    - secure environments such that applicationscan be e+ecuted securely %%% mainly2 applications aree+ecuted in well protected environments %%% what does thismean &&&

    - can one application arbitrarily interfere withanother application &&&

    - different2 isolated process address spaces (memory spaces) - * unit of the processor and critical

    core data structures achieve isolatedprocess address spaces %%% we will see thedetails during memory management %%%

    - system calls and system space management of

    critical data structures %%%- how is this achieved &&& these are achieved

    using processors capabilities - in fact2

  • 8/12/2019 Os Intro11 Class

    7/33

    many interesting features of operatingsystem are due to processors capabilities %%1

    - it uses more than * capability of theprocessor %%%

    - ofcourse2 operating system can program/reprogram

    these facilties as per its reuirements - processors provide such a suitable interfacing %%% - many of these low level control code are present in the :!" of the operating

    system core %%%(hardware abstraction layer)

    ;. operating system is made up of several components - it is a verylong list and each component is uite comple+ and may reuire

    a separate study of its own - one good e+ample is memory subsystem

    - another comple+ and vast sub-system is /O- our study will mainly focus on certain corecomponents - once you understand the woringand usage of core components2 understandingnon-core components is easier - even understandingother core components becomes easier %%%

    - typical operating system boos focus on corecomponents - other professional boos thatdeal with certain services of an operating systemmay deal more with non core components %%%

    - there are professional references that deal more specifically with one or more core/non-core components %%% - your case may involve studying a specific R9O3/8O3 and its interfaces - it may also involve studying and

    using a specific add on component in that R9O3 2 whichmay be useful in your domain/wor %%%

    Note7(analogy could be a processor chip or any otherperipheral controller chip %%%)

    - core components are made up of system space code and system space data structures / ob$ects %%% - governed by strict architectures2rules and mechanisms %%%

    - can you see the system data structures/ob$ects && - say a process descriptor(related)2 for instance %%% - humanly2 not %%% may be a super -human %% - micro level details cannot be seen %%%

    - visualiation will happen with practicals %%

    - can you access system data structures/ob$ects &&&

  • 8/12/2019 Os Intro11 Class

    8/33

    - via system utilities2 system calls and other interfaces%%% - utilities and system calls provide services and also provide access to

    system space information %%% - can we literally access using our code &&&

    - ernel debuggers/tools (&&&)- writing your own system call code orwriting your own ernel module %%% this istypically achieved using system space coding

    and you may need to such wor2 if reuired %%%

  • 8/12/2019 Os Intro11 Class

    9/33

    -- static reconfiguration(during practicals) - less fle+ible- adding/removing ernel modules to the core of the system %%%

    (no need to restart the system - run-time dynamic loading ) -- dynamic reconfiguration(during practicals) - more fle+ible

    >. some of the layers interact very closely with the processor/ h/w controllers -

    one such is :!" - hardware abstraction layer - /O subsystem and device drivers are ma$or contributors to interaction with h/w

    controllers %%% - :!" is a layer/component of core of operating system %%% - /O subsystems(may be several layers /modules)

    manages drivers and devices(logically) - :!" is written in machine language

    - drivers are more in high-level language and specificto a specific device controller - drivers use :!"to accomplish their wor

    - there are many other core components that interact/ use :!" to accomplish their wor

    - depending upon underlying processor arch./board2 :!" will be different for a given operating system - if

    a given O3 has a specific :!" for a specificarch/board2 that O3 can be loaded to manage the correponding

    arch/board - otherwise2 it is not possible %%% - the above is nown as portability

    - we will see more during 8O3 study %%%

    Note 7 in what ways ,Os may be different from R9O3 && in what ways ,O3 may be different from 8O3 &&& in what ways a given ,O3 may be different from another ,O3 && in what ways a given R9O3 is different from another R9O3 &&& - say for e+ample2 a given R9O3 may implement

    interrupt handler as an asynchronous method2 not a tas %%%

    - another R9O3 may implement interrupt handler asa ernel thread/tas %%%

    - hw timer management may be different- sw timer management may be different- one R9O3 may provide system space tass only- another R9O3 may provide user-space tass and system space

    tass %%% - whenever we discuss about os differences2 it will be

    more on their core services2 not on add on services -

    it does not mean2 add on services should not be discussed- it is the core services that have more impact when there are changes and add on services can come and go %%%

  • 8/12/2019 Os Intro11 Class

    10/33

  • 8/12/2019 Os Intro11 Class

    11/33

    these (application programming interface / application programmersinterface) system call !,s are implemented using system library and system

    call interface layer of the operating system %%% system call !,s

    are dependent on interrupt handling mechanism of the underlyingh/w and operating system as well %%%

    - we may use operating system services directly or indirectly %%% - directly means2 your code uses system call !,s - indirectly means2 your code invoes library/framewor !,s and they in turn invoe system call !,s

    - we will be abe to use and able to use efficiently2 ifwe understand the woring of ther services and their limitations%%%

    - we will be able to understand problems and bugs %%%

    - certain operating system services can only be accessed using system call !,s - you will see more of this during practicals %%% - we may be able to increase performance of our applications%%% - by using certain special services directly2 if needed %%%

    11. for the above reasons and also for understanding other activities of the operating system2 interrupt mechanism and interrupt handling must be understood2 in the conte+t of O3/R9O3/8O3 %%% - if you are a real time systems engineer2 you better learn

    about interrupt handling and many such low level mechanisms %%% - this will enable you to understand critical control sections in a computing system and enable to fine tune computing

    for real time programming %%%- developers dealing with /O subsystems and device drivers

    must also study about the above %%%

    14. operating system may be seen as ernel 2 libraries and utilities2in a computing system - ernel contains the core components of the

    operating system - typically2 process mgmt.subsystem2

    physical mm. mgmt.subsystem 2virtual mem. mgmt.2 file management subsystems2 logical file

    management subsystem2 /O subsystems 2 device drivers2 interrupt subsystem2 ,' subsystems2 9imer subsystem and many more %%% - :!" is the lowest layer (logically) in the core

    components that interacts very closely with processor and may be responsible for the following activities7 - * management / interaction

    - low-level interrupt handling - :!" will be doing the second level hw

    conte+t saving

  • 8/12/2019 Os Intro11 Class

    12/33

    - :!" may be involved in interacting withinterrupt controller(s)

    - :!" may be involved in controllingprocessors hw interrupt enabling/disabling

    - low - level system call handling

    - low level process conte+t switching- low-level e+ception handling- many /O subsystem related - we will see moreof this during /O buses %%%

    - there can be several /O subsystems in the coreof the O3

    - each /O subsystem is responsible for managingdevices and drivers under the given category ofdevices %%

    - it is typically the /O subsystems and device drivers that interact with :!" as well - other componentsalso interact2 as reuired %%%

    - /o subsystem and drivers are more to dowith peripheral controllers and their

    management- :!" $ust helps in interaction with peripheral

    controllers %%% - on the other hand2 :!" is also responsible

    for managing / interacting with processor /interrupt controllers with the help of other subsystems of the core of the O3 %%%

    - subsystems and managers are terms used interchangeably %%% - there are many subsystems and many components %% - what is a subsystem && - ernel is the system here %%% ernel is a subsystem of O3 - O3 is a s/w subsystem of computing system %%%

    - computing system will be a subsystem of your real system %%% that real system may be a plant in the industry %%% - a component in a ernel is nown as subsystem - there can be one or more components managed by a subsystem - a good e+ample for a component is devicedriver%% - one more good subsystem is interrupt subsystem %%% - one more good component is a specific scheduling policy/ algorithm %%% there can be several scheduling

    policies(components) implemented in a given ernel of an operatingsystem %%%these mae up

    the scheduling subsystem (generic scheduler)

  • 8/12/2019 Os Intro11 Class

    13/33

    Note7 there are typically 4 types of ernel architectures %%% one is nown as monolithic ernel architecture

    and the other is nown as microernel(&&) architecture %%% - in this discussion2 we will be looing at practical

    usage of such architectures rather than the theoretical

    definitions %%% - monolithic ernel arch7

    - all the core components are said to be builttogether into a single large image

    (ernel image/a special program ) that isloaded into the main memory2when the systemis started/booted %%% during the life of asystem boot2 all the core components reside

    in the main memory and cannot be unloaded %%%

    - this is a less fle+ible arrangement formost systems %%% - we will understand more during ernel

    reconfiguration %%%

    - to provide fle+ibility and convenience2 a monolithic-ernel/ modular ernel arch. was introduced %%% - most essential(&&) core components are built

    into a single image that is loaded duringthe system startup/booting %%

    - additional(&&) core components can be added/removed to/from the system space as per the systems

    reuirements %%% this may be done manually or automated %%% it is a fle+ible arrangement %%% - the added component is a passive entity-it is

    not a process / thread / ernel thread %%%- $ust loaded2 with some lining %%%

    - in certain microernels2 a core component maybe added and this core component may contain

    one or more tass %%% this is little more thana module %%% added component is an activeentity %%%

    - what is the difference between a module and a module that may contain several

    tass &&&- a typical module contains $ustmethods and data - when loaded2these methods and data are loaded

    into system space %%% - this is one form of microernel %% - a more sophisticated module may

  • 8/12/2019 Os Intro11 Class

    14/33

    create several tass2 when loaded - this is in addition to loading

    methods and data into system space %%% - this is another form of microernel

    Note7 a computing BtasB is a schedulable entity2 which may be a a process or a thread or some other entity(which may

    be a 8O3/R9 tas / ernel thread or some distorted form )%%%16. the following is the summary of the big picture in

    linu+CernelCinternalsCconceptsCintro.pdf %%%

    - system call interface layer provides a trap handler that is

    invoed whenever a system call !, is invoed - as per thesystem call !, and its rules2 trap handler with the help of system call table (also located in system call interface layer) will invoe appropriate system call system routine in the

    appropriate sub-system of the ernel - in the e+ample shown2 process management subsystem is in use %%%

    - in the same picture2 process management subsystem is shown asdependent on :!" layer - process management subsystem isalso supposed to contain cpu scheduler2 in this picture -in our discussions2 cpu scheduler will be treated as a separatesubsystem - cpu scheduler also is dependent on :!" layer forsome of its activities - one such is process conte+t switching %%%

    - the top most layer of memory management may be treated asprocess memory manager/virtual memory manager %% lower layerof memory management may be treated as physical memory

    manager%%%

    - top most layer of file management may be treated as logicalfile manager - this is supposed to manage different file systemmanagers2 which will inturn be responsible for managing different

    types of file systems %%%

    - bloc device management may be treated as an /O subsystem and device drivers for various bloc devices are also managed via bloc device management %%%

    - bloc devices have certain rules for data transfer - they cantransfer data with the ernel in multiples of appropriatebloc sie - they cannot transfer arbitrarily sied data

  • 8/12/2019 Os Intro11 Class

    15/33

    - in the same picture2 character/ byte devices are shown - character devices may transfer data in arbitrary sies as per theirreuirements - this is one of the ma$or differences with respect tobloc devices-

    we will se more of this during file management %%%

    - this picture is not complete - there are many other subsystems and their own hierarchy and layering - still2 this picture can be a

    good starting point %%%

    1;. following is the summary for the class room big picture 7

    - in the picture2 there is a dotted line at the top separating

    user-space and system-space %%% to start with2 some parts of physical memory are used for user-space and other parts are used for system - space - however2 it is more complicated in the conte+t of virtual memory systems - we will see more

    of this during memory management %%% it may also be slightly different for R9O3/8O3 environments %% - user-space may be seen as a set of memory regions with a

    set of hw(*) attributes %% in the future2 you may use ,* related features2 if needed %%% - system space may be seen as a set of memory regions with another

    set of hw(*) attributes %% (may have ,* related features) - the attribute settings are taen care by the ernel2 as per

    rules of h/w(processor) and O3 %% for clarity2 refer to64-bit/=;-bit processor architectures - in particular2refer to !R corte+-6 architecture to start with(or another

    architecture) %%% - these attributes are managed by memory managementsubsystem(of O3) -

    it is accordingly set for user-space attributes or system space

    attributes %% processor is responsible for these attributes and operating system e+ploits these attributes %%% this is achieved using a set of data structures and certain settings in the data structures %%% - in addition2 there is a separation between the 4 spaces and

    their respective components via priviliges - user-space andits components have lesser priviliges and system-space andits components have higher priviliges - this privilige setting

    is controlled via a set of control bits in one of the processors

    control registers - again2 this control is also done by ernel -we will

    see more of this during interrupt handling and system call

  • 8/12/2019 Os Intro11 Class

    16/33

    handling %%% - user-space and system space division is one mechanism-

    achieved using a h/w techniue by the ernel -this is more to do withattributes set with respect to memory regions - we will see

    more of this during memory management %%%

    - lesser privilige of user-space components vshigher privilige of system-space components isa different mechanism - achieved using another

    h/w techniue by the ernel - this is more to do with cpus privilige settings %%% this is more to do with cpus privilige mode %%%

    - however2 they are related %%%

    - system-space components(when processor is e+ecuting inpriviliged mode)

    have the following priviliges7 - can access any part of the memory of the system

    as per rules of the system - can access any machine instruction(priviliged) of the underlying

    architecture- can access peripheral h/w controllers andregisters as per rules - can also access any control register

    of the underlying processor %%

    - user-space components have the following restrictions7 (when processor is e+ecuting in less priviliged mode ) - can access only user-space regions of memory sub$ect to other rules %%

    - cannot access all machine instructions of the underlying

    architecture - what happens if a priviliged machine instruction

    is used in an user-space component && - processor will generate hw e+ception and

    os will handle the e+ception %%% mostly2 process will be abnormally terminated %%% - cannot access h/w controllers and registers without

    system calls and help of the ernel components %%- not all system calls can be e+ecuted by

    all processes/programs/applications - there are further rules of the operating system2 in addition to the above rules %%%

  • 8/12/2019 Os Intro11 Class

    17/33

    - in addition2 system may not e+port allservices via system call !,s %%

    1

  • 8/12/2019 Os Intro11 Class

    18/33

  • 8/12/2019 Os Intro11 Class

    19/33

    priviliged mode of operation %%% stac is switched bac %% registers(old e+ecution conte+t ) is restored - cpu

    $umps bac to an instruction in the application andresumes e+ecution of application normally

    - this seuence of actions are repeated for every h/w

    interrupt and several such interrupts may occurin one second - these activities are seamless tothe user and developer of the system2 but theydo productive wor on behalf of device-drivers/subsystems and

    applications %%

    Note7 priviliged mode of processor vs less priviliged mode ofprocessor is critical for understanding certain aspects

    of operating system - we will see more along with

    system space and user space features %%%% - processor is e+ecuting in less priviliged mode - canwe say that active applications/processes e+ecute whenprocessor is in less priviliged mode %%

    - processor is e+ecuting in priviliged mode - can we saythat components of core of operating system e+ecutewhen processor is e+ecuting in priviliged mode %%%

    - privilige here means2 corresponding components/code can interact with any hw controller and processor %%%

    - meaning2 they have full privilige to manipulate hw resources %%% - they have full priviliges in using resources %%% - they have privilige to access any part of the

    computing systems memory space %%%

    1=. system call !,s use interrupt mechanism to implementtheir special $umps - system call !,s use a special machine

    instruction of the underlying architecture to implementa special $ump similar to h/w interrupts - in this case2

    h/w signal is not generated by an e+ternal peripheral2 but a special $ump is generated by a machine instruction %%Note7 swi and svc are special machine instructions that you will come across during !R> / !R corte++ study %%%Note7 in the case of +?=2 you may encounter other machine

    instructions - one such is BintB instruction %%%Note7 refer to syscallCfor.cpp or syscallCfor1.cpp or syscallCfor.s under e+amples/ directory %%% - most of the steps mentioned for h/w interrupt handler

    are also applicable for this mechanism - there are certain differences between the two mechanisms- one such is in the interrupt handling part

  • 8/12/2019 Os Intro11 Class

    20/33

    - in the case of system call !,s2 the corresponding interrupt handler will pass control of e+ecution to appropriate

    system call system routine of appropriate subsystem - thisis done with the help of system call no. which is e+plicitlypassed by system call !, and using system call table

    - each /O interrupt has one interrupt handler in the interrupt table - /O interrupt no. is implicitly

    generated based on the interrupt signal lineon which interrupt event was generated - to now

    more2 e+plore interrupt controller subsystem of!R architecture %%

    - all system call !,s end up accessing the samesystem call interrupt handler - it is the responsibility

    of the system call interrupt handler to invoe appropriate

    system call service routine using system call table %%

    - in a modern day O32 there can be several system call !,s -easily2 1AAs of !,s - each is assigned a fi+ed system call

    no. and encoded in its system call !, - there is one entry for each system call !, in the system

    call table and it is inde+ed by the corresponding systemcall no. - the corresponding entry contains pointer tocorresponding system call system routine %% very ob$ective

    of system call !, is to invoe a specific service ofa subsystem of O3 - in the case2 of /O interrupt handler

    2 they process /O data and in addition2 interact withanother subsystem of O3 for further activities - do notconfuse their architectures %%%

    - additional system call !,s and their code maybe added by a silled developer2 if needed %%%

    - a typical R9O3 system may provide certain special2 sophisticated system call !,s that can provide

    more control for the applications and thesesystem call !,s may not be typically availablein a typical ,O3 system %%%%

    - we will be writing code that will bepart of system call e+ecution %%%

    - we will be using the term system call(s) very often -this means2 a system call !, and its associatedsystem call system routine D any other code

    that is involved in e+ecution %%%

    - we will be saying that a system call is e+ecuting - thismeans2 a system call !, is invoed and correspondingsystem call system routine is e+ecuting in system space %%%

  • 8/12/2019 Os Intro11 Class

    21/33

    Note7 why interrupt handlers2 interrupt subsystem2 system calltable and system call system routines are loaded in system

    space &&& - these are e+pected to be priviliged %%

    - these components must be isolated and protectedfrom user-space developers %%%

    Note7 one of the best ways to learn operating systems/(gpos/rtos) is to learn around an entity or a mechanism that provides functionally useful services to applications %%% one such

    entity that you may benefit for study as well wor isthe process %%% one more such entity that you may benefitis the memory resource %%%

    1>. process management %%

    - who is responsible for the creation of the first process &&& - ernel is responsible for creating the initial set

    of processes(during boot-up) -particularly2 init process is the firstuser-space process created by the ernel without usersintervention %%% although2 the init process may becustomied by operating system developer %%% these system

    processes are typically created during boot up of the operating system %%%note 7 refer to chapter< of 'rowley for an illustrative diagram %%% - eventually2 this first process will e+ecute certain system

    scripts and provide us an environment for building ourapplications and loading our applications %%%

    - once such an environment is created2 any further processes are created directly or indirectly(system utilities/tools/libraries) via system call !,s %%

    - before understanding process creation2 termination and itsstates2 we must understand what is a process from systempoint of view - this is typically nown as process managementactivities %%%%

    - from a user space point of view2 process is an active applicationor a program %%%

    - refer to slides in day1 %%%

    1?. following is the description of a process from a system point ofview 7

    - each process in the system is represented and managed via a

  • 8/12/2019 Os Intro11 Class

    22/33

    process descriptor in the system space %%%process manageris responsible for creating pds and managing pds %%%

    - what is a pd2 in computing terms - the best term ispd can be called as a system ob$ect %%%

    note 7 let us assume that pd(process) is a schedulable entity as well

    as an entity that manages resources on behalf of processes %%

    - each process in the system is allocated an uniue process descr. (pd) - each pd contains information/details of a process and

    also contains several nested ob$ects 2 which in turn describe several resources and information

    - pd typically contains following info 7 - process id

    - process state

    - hw conte+t area (contains initial hw conte+t(processor

    registers) andsaved hw conte+t )

    - scheduling parameters - policy2 priority and time-slicedetails

    - each process has an user-space stac and a system space stac - information regarding stacs are maintained

    as part of pd %% - maintains system stac address of this process -

    run-time conte+tis maintained for a process in system - stac -can you name a process state when system stac is used &&&

    - bloced state //waiting state %%% - during system call $ump/e+ecution %%% - during interrupt handling / e+ecution %%%

    - maintains addresses of active files of this process - maintains memory descriptor

    - memory descriptor maintains other descriptors thatdescribe virtual memory/logical and physical memory of

    s the process - maintains the setup of process layout2in user-space %%%

    - pd contains fields that help the system to maintain several lists of pds as per state information

    - ready state - maintains all pds in ready state in a ready ueue(scheduler) %%% one ready ueue e+ists per processor %%%

    - different waitueues e+its for differentresources %%% one waitueue may e+istper /O data channel %%%(drivers/ipcs/networ)

  • 8/12/2019 Os Intro11 Class

    23/33

  • 8/12/2019 Os Intro11 Class

    24/33

    - each pd is assigned an uniue id nown as pid - mostprocess mgmt. system calls and ernel space code use pid

    to identify a process / pd - we will be encounteringpid usage in many scenarios

    Note 7 a process may be defined as below 7 - an active application that is loaded in the user-space of

    the system and is managed with the help of system ob$ects - system ob$ects include pd and related nested ob$ects -

    pd mainly maintains info. for managing the process and nested ob$ects manage info related to resource management for the process - in short2 a process will have memory allocated

    in user space for code/data/heap/stac/other segments(regions)(

    code and data contents are loaded from associated application/ program) and

    in system space for pd and related ob$ects %%% - an active instance of an application is typically nown as

    a process- process is an operating system entity controlled by theprocess manager and other subsystems %%%

    Note7 operating systems are more comfortable using ids rather than names - for most entities2 operating systems will be using ids rather than names %%%

    Note7 after a process is created2 it ob$ects are created2 state of pd is set to ready and pd is added to ready ueue of the

    current processors scheduler%%%

    Note7 ',* scheduler may viewed as following 7 - a set of methods to implement the scheduling policy or polices - a set of ob$ects/data structures used to manage ready ueue 2pds and other run time scheduling information %%% - when a process is created2 it is added to ready2 but may

    be not scheduled2 immediately -it also depends on the implementationand scheduling parameters %%% again2 these may differ from oneO3 to another O3 - may differ from gpos to R9O3 %%%%

    - scheduler() is responsible for moving a process fromready state to running state - meaning2 scheduling the

  • 8/12/2019 Os Intro11 Class

    25/33

    process %%% who is responsible for scheduling the scheduler &&& - in most operating systems(including R9O3)2 scheduler

    is typically invoed after a hw interrupt and aftercompleting the processing of interrupt handler on behalfof a given hw interrupt event %%%

    - in addition2 in most operating systems(including R9O3)2scheduler is typically invoed after a system call!, or a system !, - however2 for the current discussion2let us assume the first case - meaning2 hw interrupt processingfollowed by scheduler() getting invoed %%%- system !,s are provided by components/layers ofsystem space - a component may use system !, ofanother component or layer - you may come across

    these in R9O3 systems as well2 depending upon

    the wor and the environment offered by respectiveR9O3 %%%

    - state of a process is another important info. usedby the system in maintaining processes - typically

    following states are common7 - Ready - process is in ready state and in ready ueue

    - Running - process is scheduled on the processorNote7 if a process is said to be scheduled on the processor2 what

    does this really mean &&& let us assume that scheduler decides which process must be scheduled on the processor based on

    a scheduling policy - in our case2 let us assume that itis first come first serve and let us also assume thata fi+ed time slice/uantum is given to the process2 when it is

    scheduled %%% - this also involves dispatching the process on the processor %%% - loading the processors registers with the values of the conte+t of the process stored in the system

    stac of the process %%% these registers may include

    program counter2 stac pointer2 general purpose registers and several control registers of the processor

    - we will see some more fine details during another conte+tof discussing %%%

    - once a process is dispatched by the scheduler on to theprocessor2 whatever happens to the process instructions/datainside the processor2 operating system is immune or ignorant %%%

    - bloced/waiting

    - stopped - a developer or administrator or operating system

    may wish to e+plicitly and forcibly

  • 8/12/2019 Os Intro11 Class

    26/33

    stop a process for convenience and resume the process whenneeded %% (vert common in R9O3/8O3 environment )

    when a process is stopped2it is moved from ready ueue and pds state is set to stopped -

    it is not maintained in any wait ueue - its resources are not

    freed - still managed in the pd and when resumed2 pd will bemoved to ready ueue

    - depending upon the environment that you may wor2 you maynot

    see stopped state - however2 $ust be aware %%%

    - terminated

    - may have encountered a fatal processor e+ception

    - we may forcibly terminate a process - if a process has completed its wor2it may terminate voluntarily using aprocess termination system call !, %%

    - a developer may have to code this e+plicitlyor compiler may add this system call !, 2

    implicitly %%%- first 4 are nown as abnormal terminatiomn- last one is nown as normal termination

    - whether normal or abnormal termination2 allresources of the process are freed bac tothe system %%% the process does not e+istin the system %%%

    - the above are commonly used states - other states doe+ist in real systems and they may be e+tensions ofcommon states - in a typical "inu+ system2 followingstates are in use 7

    - Running/runnable

    - interruptible wait - uninterruptible wait - stopped - ombie - dead

    &&&& - when a process is running on the cpu(after scheduling)2

    it may reuest for logical/physical resources -if the resource is available2

    process will be allocated the resource and it willprogress - if the resource is not available(busy wait

    or blocing wait)2 ernel

  • 8/12/2019 Os Intro11 Class

    27/33

    changes the state of the process to one of the waitstates and also adds the process to the appropriatewait ueue %%% bloced state is due a system call !,2

    which is invoed by a process to reuest for a logical resource or /O resource %%% it is actually the respective

    system call !,/ e+ecution that is responsible forblocing the current process2 as described above %%%

    - resources may be of different types - reading data from a file on dis is

    is also one type of resource reuirement - trying to allocate memory /dynamically

    is also one type of resource reuirment- trying to access an /o device fordata is also one type of resource reuirement

    - trying to acuire a loc(,') is also one type ofresource reuirement %%1 -depending on the conte+t 2 you may encounter several such situations %%% - in a typical operating system2 a process

    may reuest for resource via system call !,s %%% - in a typical R9O3 environment2 you may use

    sw timers to implement precise delays/time outs %%% - waiting/sleeping for time out in a sw timer2 is also one form of blocing - this may not be for a resource %%% - in some cases2 you may bloc also for

    synchroniation2using O3/R9O3 mechanisms %%%

    - when the appropriate resource is available2 ernelwill wae-up the process - state of the process willbe changed to ready state and pd will be removed fromwait ueue - pd will be added to ready ueue- a system call !, may be responsible for

    wae up of a process &&& - another process may have released the reuired

    resources E - memory may be available - an /O device may be available - a loc may be available - a synchroniing semaphore may be

    incremented/signalled- an interrupt/interrupt handler may be responsible

    for wae up of a process && - if the resource has an /O activity associated with it %% such wae-ups are very common

  • 8/12/2019 Os Intro11 Class

    28/33

    in R9O3 %%% - once in the ready ueue2 a process/pd will be scheduled

    by the scheduler as per its merit

    - when a process is scheduled(policy is timeslice/timeshare)

    and running on the processor2it may be preeempted by the ernel2 if it has e+haustedits time-slice/time-share - it may be preempted2 if another

    process with higher priority is woen-up %%

    - a process is said to be preempted2 if the process isforcibly removed from the processor2 its state ischanged to ready and its current hw e+ecution conte+t issaved in the system stac of the process %%% in addition2

    a new process is loaded on the processor - meaning2 hw conte+t of a newly selected process is loadedon the processor %%%

    - who is responsible for preemption2 in these conte+ts &&& - for the case of time-slicing/time sharing %%% - timer interrupt handler(hw timer generated) D

    scheduler- timer interrupt handler is responsible for

    maintaining time share/time slice of thecurrent process %%%

    - how does the timer interrupt handlermanage time slice of the current process &&&

    - we will see in the timer int handler %%

    - for the case of higher priority process beingwoen up %%%%

    - a system call !, D scheduler - a system2 call !, may release a loc

    and implicitly wae up a process-a higher priority process waiting for the released loc is woen up and added to ready state%%%

    - or an /O or timer interrupt handler D scheduler- a higher priority process may be woen upfrom a sw timer

    - a higher priority process may be woen up due to /O data availability %%%

    - when a process is preempted2 its state will be changed to

  • 8/12/2019 Os Intro11 Class

    29/33

    ready and it will be added to ready ueue2 not wait ueue %%

    - the above process life cycle continues - at any point of

    time2 there are several processes in the system - processes/pds are scattered in different states and corresponding

    lists/ueues- pds and associated ob$ects reuire physical memory an d

    this is allocated from phy. mem manager 2 not 0 -0 along with , will allocate physical memory for

    user-space sections of the process using virtual memorytechniues %%1

    - process creation may be defined as follows 7

    - a new pd is created - a new pid is allocated - a program is associated with the pd

    - other resources and ob$ects are allocated andadded to the pd (&&&)

    - state of the process is changed to ready - pd is added to one or more lists of the process management in the system

    - the above resources and ob$ects of a pd are maintainedas long as the process is not terminated

    - when a process is terminated normally or abnormally2resources2 ob$ects and pd of the respective process

    are freed by the system- there are specific system call !,s involved in process

    creation and process termination - different !,s may be involved depending upon certain conditions of creation

    and termination %%- a process is normally terminated when the correspondingcode/application e+ecutes the appropriate system call !,2

    directly or indirectly %%% - how do we understand the behaviour of abnormal process termination && - if a process does not respond or does not function as e+pected2 it is normal for users/developers/administrators to forcibly terminate the process - such forcible termination

    is done using a system call / system utility to notify /signal the respective process %%% - if a process attempts illegal activities(as mentioned

    in class)2 processor generates an h/w e+ception - ah/w e+ception will lead to interrupt behaviour and corresponding

    e+ception handler is invoed %%

  • 8/12/2019 Os Intro11 Class

    30/33

  • 8/12/2019 Os Intro11 Class

    31/33

  • 8/12/2019 Os Intro11 Class

    32/33

  • 8/12/2019 Os Intro11 Class

    33/33