UNIT 2 and UNIT 3 (2 Mark Answer)

download UNIT 2 and UNIT 3 (2 Mark Answer)

of 14

Transcript of UNIT 2 and UNIT 3 (2 Mark Answer)

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    1/14

    UNIT 2 and UNIT 3

    Part - A

    1. What is a thread?

    A thread otherwise called a lightweight process (LWP) is a basic unit o !PU utili"ation#it co$prises o a thread id# a progra$ counter# a register set and a stac%& It shares with

    other threads belonging to the sa$e process its code section# data section# and operating

    s'ste$ resources such as open iles and signals&

    2. What are the benefits of multithreaded programming?

    The beneits o $ultithreaded progra$$ing can be bro%en down into our $aor

    categories

    *esponsi+eness

    *esource sharing

    ,cono$'

    Utili"ation o $ultiprocessor architectures

    3.Compare user threads and kernel threads.

    User threads Kernel threads

    User threads are supported abo+e the %ernel and arei$ple$ented b' a thread librar' at the user le+el

    ernel threads are supported directl' b' the operating s'ste$

    Thread creation . scheduling are done in the userspace# without %ernel inter+ention& Thereore the' areast to create and $anage

    Thread creation# scheduling and $anage$ent are done b' theoperating s'ste$& Thereore the' are slower to create .$anage co$pared to user threads

    /loc%ing s'ste$ call will cause the entire process tobloc%

    I the thread peror$s a bloc%ing s'ste$ call# the %ernel canschedule another thread in the application or e0ecution

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    2/14

    4.Define thread cancellation target thread.

    The thread cancellation is the tas% o ter$inating a thread beore it has co$pleted& Athread that is to be cancelled is oten reerred to as the target thread& 1or e0a$ple# i

    $ultiple threads are concurrentl' searching through a database and one thread returns the

    result# the re$aining threads $ight be cancelled&

    !.What are the different "a#s in "hich a thread can be cancelled?

    !ancellation o a target thread $a' occur in two dierent scenarios

    Asynchronous cancellation:ne thread i$$ediatel' ter$inates the target thread

    is called as'nchronous cancellation&

    Deferred cancellation:The target thread can periodicall' chec% i it should

    ter$inate# allowing the target thread an opportunit' to ter$inate itsel in an

    orderl' ashion&

    $.Define C%U scheduling.

    !PU scheduling is the process o switching the !PU a$ong +arious processes& !PU

    scheduling is the basis o $ultiprogra$$ed operating s'ste$s& /' switching the !PU

    a$ong processes# the operating s'ste$ can $a%e the co$puter $ore producti+e&

    &.What is preempti'e and nonpreempti'e scheduling?

    Under nonpree$pti+e scheduling once the !PU has been allocated to a process# the

    process %eeps the !PU until it releases the !PU either b' ter$inating or switching to the

    waiting state&

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    3/14

    Pree$pti+e scheduling can pree$pt a process which is utili"ing the !PU in between its

    e0ecution and gi+e the !PU to another process&

    (.What is a Dispatcher?

    The dispatcher is the $odule that gi+es control o the !PU to the process selected b' the

    short-ter$ scheduler& This unction in+ol+es

    witching conte0t

    witching to user $ode

    4u$ping to the proper location in the user progra$ to restart that progra$&

    ).What is dispatch latenc#?

    The ti$e ta%en b' the dispatcher to stop one process and start another running is %nown

    as dispatch latenc'&

    56&What are the +arious scheduling criteria or !PU scheduling7

    The +arious scheduling criteria are

    !PU utili"ation

    Throughput

    Turnaround ti$e

    Waiting ti$e

    *esponse ti$e

    11.Define throughput?

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    4/14

    Throughput in !PU scheduling is the nu$ber o processes that are co$pleted per unit

    ti$e& 1or long processes# this rate $a' be one process per hour8 or short transactions#

    throughput $ight be 56 processes per second&

    12.What is turnaround time?

    Turnaround ti$e is the inter+al ro$ the ti$e o sub$ission to the ti$e o co$pletion o

    a process& It is the su$ o the periods spent waiting to get into $e$or'# waiting in theread' 9ueue# e0ecuting on the !PU# and doing I:&

    13.Define race condition.

    When se+eral process access and $anipulate sa$e data concurrentl'# then theoutco$e o the e0ecution depends on particular order in which the access ta%es place is

    called race condition& To a+oid race condition# onl' one process at a ti$e can $anipulate

    the shared +ariable&

    14.What is critical section problem?

    !onsider a s'ste$ consists o ;n; processes& ,ach process has seg$ent o code called a

    critical section# in which the process $a' be changing co$$on +ariables# updating a

    table# writing a ile& When one process is e0ecuting in its critical section# no other processcan allowed to e0ecute in its critical section&

    1!.What are the re*uirements that a solution to the critical section problem must

    satisf#?

    The three re9uire$ents are

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    5/14

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    6/14

    boolean te$p > a8

    a > b8

    b > te$p8

    ?

    1(.What is semaphores?

    A se$aphore ;@ is a s'nchroni"ation tool which is an integer +alue that# apart ro$

    initiali"ation# is accessed onl' through two standard ato$ic operations8 wait and signal&

    e$aphores can be used to deal with the n-process critical section proble$& It can be alsoused to sol+e +arious s'nchroni"ation proble$s&

    The classic deinition o ;wait@

    wait ()

    =

    while (>6)

    8

    --8

    ?

    The classic deinition o ;signal@

    signal ()

    =

    BB8

    ?

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    7/14

    1).Define bus# "aiting and spinlock.

    When a process is in its critical section# an' other process that tries to enter itscritical section $ust loop continuousl' in the entr' code& This is called as bus' waiting

    and this t'pe o se$aphore is also called a spinloc%# because the process while waiting

    or the loc%&

    2-. o" can "e sa# the /irst Come /irst 0er'ed scheduling algorithm is non

    preempti'e?

    nce the !PU has been allocated to a process# that process %eeps the !PU until it

    releases the !PU# either b' ter$inating or b' re9uesting I:& o we can sa' the 1irst!o$e 1irst er+ed scheduling algorith$ is non pree$pti+e&

    21.What is "aiting time in C%U scheduling?

    Waiting ti$e is the su$ o periods spent waiting in the read' 9ueue& !PU scheduling

    algorith$ aects onl' the a$ount o ti$e that a process spends waiting in the read'9ueue&

    22. What is esponse time in C%U scheduling?

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    8/14

    *esponse ti$e is the $easure o the ti$e ro$ the sub$ission o a re9uest until the

    irst response is produced& *esponse ti$e is a$ount o ti$e it ta%es to start responding#

    but not the ti$e that it ta%es to output that response&

    23. Differentiate long term scheduler and short term scheduler

    The long-ter$ scheduler or ob scheduler selects processes ro$ the ob pool and

    loads the$ into $e$or' or e0ecution&

    The short-ter$ scheduler or !PU scheduler selects ro$ a$ong the process that

    are read' to e0ecute# and allocates the !PU to one o the$&

    24. Write some classical problems of s#nchroniation?

    The /ounded-/uer Proble$

    The *eaders-Writers Proble$

    The Cining Philosophers Proble$

    2!. When the error "ill occur "hen "e use the semaphore?

    i& When the process interchanges the order in which the wait and signal operations on

    the se$aphore $ute0&

    ii& When a process replaces a signal ($ute0) with wait ($ute0)&

    iii& When a process o$its the wait ($ute0)# or the signal ($ute0)# or both&

    2$.What is utual +clusion?

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    9/14

    A wa' o $a%ing sure that i one process is using a shared $odiiable data# the other

    processes will be e0cluded ro$ doing the sa$e thing& ,ach process e0ecuting the shared

    data +ariables e0cludes all others ro$ doing so si$ultaneousl'& This is called $utuale0clusion&

    2&.Define the term critical regions?

    !ritical regions are s$all and inre9uent so that s'ste$ through put is largel' unaectedb' their e0istence& !ritical region is a control structure or i$ple$enting $utual

    e0clusion o+er a shared +ariable&

    2(.What are the dra"backs of monitors?

    5&

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    10/14

    A two di$ensional chart that plots the acti+it' o a unit on the D-a0is +ersus the ti$e on

    the E-a0is& The chart 9uic%l' represents how the acti+ities o the units are seriali"ed&

    31.Define deadlock.

    A process re9uests resources8 i the resources are not a+ailable at that ti$e# the process

    enters a wait state& Waiting processes $a' ne+er again change state# because the

    resources the' ha+e re9uested are held b' other waiting processes& This situation is calleda deadloc%&

    32.What is the se*uence in "hich resources ma# be utilied?

    Under nor$al $ode o operation# a process $a' utili"e a resource in the ollowing

    se9uence

    *e9uest I the re9uest cannot be granted i$$ediatel'# then the re9uesting process

    $ust wait until it can ac9uire the resource&

    Use The process can operate on the resource&

    *elease The process releases the resource&

    33.What are conditions under "hich a deadlock situation ma# arise?

    A deadloc% situation can arise i the ollowing our conditions hold si$ultaneousl' in a

    s'ste$

    5&

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    11/14

    Ceadloc%s can be described $ore precisel' in ter$s o a directed graph called a s'ste$

    resource allocation graph& This graph consists o a set o +ertices H and a set o edges ,&The set o +ertices H is partitioned into two dierent t'pes o nodes8 P the set consisting

    o all acti+e processes in the s'ste$ and * the set consisting o all resource t'pes in thes'ste$&

    3!.Define re*uest edge and assignment edge.

    A directed edge ro$ process Pi to resource t'pe * is denoted b' Pi*8 it

    signiies that process Pi re9uested an instance o resource t'pe * and is currentl' waiting

    or that resource& A directed edge ro$ resource t'pe * to process Pi is denoted b'*Pi# it signiies that an instance o resource t'pe has been allocated to a process Pi& A

    directed edge Pi* is called a re9uest edge& A directed edge *Pi is called an

    assign$ent edge&

    3$.What are the methods for handling deadlocks?

    The deadloc% proble$ can be dealt with in one o the three wa's

    Use a protocol to pre+ent or a+oid deadloc%s# ensuring that the s'ste$ will ne+er

    enter a deadloc% state&

    Allow the s'ste$ to enter the deadloc% state# detect it and then reco+er&

    Ignore the proble$ all together# and pretend that deadloc%s ne+er occur in the

    s'ste$&

    3&.Define deadlock pre'ention.

    Ceadloc% pre+ention is a set o $ethods or ensuring that at least one o the our

    necessar' conditions li%e $utual e0clusion# hold and wait# no pre-e$ption and circular

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    12/14

    wait cannot hold& /' ensuring that that at least one o these conditions cannot hold# the

    occurrence o a deadloc% can be pre+ented&

    3(.Define deadlock a'oidance.

    An alternati+e $ethod or a+oiding deadloc%s is to re9uire additional inor$ation

    about how resources are to be re9uested& ,ach re9uest re9uires the s'ste$ consider the

    resources currentl' a+ailable# the resources currentl' allocated to each process# and theuture re9uests and releases o each process# to decide whether the could be satisied or

    $ust wait to a+oid a possible uture deadloc%&

    3).What are a safe state and an unsafe state?

    A state is sae i the s'ste$ can allocate resources to each process in so$e orderand still a+oid a deadloc%& A s'ste$ is in sae state onl' i there e0ists a sae se9uence& A

    se9uence o processes P5#P2#J&PnK is a sae se9uence or the current allocation state i#

    or each Pi# the resource that Pi can still re9uest can be satisied b' the current a+ailableresource plus the resource held b' all the P# with i& i no such se9uence e0ists# then the

    s'ste$ state is said to be unsae&

    4-.What is banker6s algorithm?

    /an%er@s algorith$ is a deadloc% a+oidance algorith$ that is applicable to aresource-allocation s'ste$ with $ultiple instances o each resource t'pe& The two

    algorith$s used or its i$ple$entation are

    Safety algorithm:The algorith$ or inding out whether or not a s'ste$ is in a sae state&

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    13/14

    Resource-request algorithm:i the resulting resource-allocation is sae# the transaction is

    co$pleted and process Pi is allocated its resources& I the new state is unsae Pi $ust wait

    and the old resource-allocation state is restored&

    41.Define logical address and ph#sical address.

    An address generated b' the !PU is reerred as logical address& An address seen b' the

    $e$or' unit that is the one loaded into the $e$or' address register o the $e$or' isco$$onl' reerred to as ph'sical address&

    42.What is logical address space and ph#sical address space?

    The set o all logical addresses generated b' a progra$ is called a logical address space8

    the set o all ph'sical addresses corresponding to these logical addresses is a ph'sicaladdress space&

    43.What is the main function of the memor#5management unit?

    The runti$e $apping ro$ +irtual to ph'sical addresses is done b' a hardwarede+ice called a $e$or' $anage$ent unit (

  • 8/13/2019 UNIT 2 and UNIT 3 (2 Mark Answer)

    14/14

    4!.Differentiate deadlock and star'ation.

    A set o processes is in deadloc% state when e+er' process in the set is waiting or

    an e+ent that can be caused onl' b' the other process in the set&

    tar+ation or indeinite bloc%ing is a situation where processes wait indeinitel' within

    the se$aphore&

    *ead $ore !522 - P,*ATINM DT,