SlideShare une entreprise Scribd logo
1  sur  17
INTERPROCESS
          COMMUNICATION




(M.SC Computer Science)




13/05/12             GROUP - F   1
OUTLINE

     WHAT IS IPC
     ABOUT RACE CONDITION
     CRITICAL REGIONS
     MANAGE RACE CONDITION
     DINING PHILOSOPHER PROBLEM
     MESSAGE PASSING




05/13/12                GROUP I    2
What is IPC ?

     Processes frequently need to communicate with other
      processes.

     Generally shared memory is used to establish the
      connection among processes.

     This memory must be shared carefully to avoid
      inconsistency.



13/05/12                     GROUP - F                      3
IPC: Race Condition

                       Spooler directory
                              .
                                                           . Race condition :-
                                                  out= 4
                          4       abc                      The situation where two
                                                           or more processes are
           Process A      5       prog.c                   reading or writing some
                                                   in =6   shared data is called race
                          6                                condition.

           Process B
                                     .
                                     .
                                     .

            Two processes want to access shared memory at same time
13/05/12                                   GROUP - F                                4
IPC: Critical Regions
Critical Region/ Critical Section
     The part of the program where the shared memory is
     accessed is called the critical region.
           conditions to provide mutual exclusion
             No two processes will be in critical region
              simultaneously.
             No process running outside its critical region
              may block another process.
             No process must wait forever to enter its
              critical region.

13/05/12                       GROUP - F                       5
How to Manage Race Condition ?

      Mutual Exclusion with Busy Waiting
           Strict Alternation
      Mutual Exclusion without Busy Waiting
           Sleep and wakeup
           Semaphore
           Message Passing



13/05/12                         GROUP - F     6
STRICT ALTERNATION
while(TRUE)                         while(TRUE)
{                                   {
  while(turn!=0) /* loop /;                while(turn!=1) /* loop */
   critical_region();                    critical_region();
   turn=1;                            turn=0;
   noncritical_region();              noncritical_region();
  }                                 }




           Process A                           Process B
            DRAWBACK: wastage of CPU time by Busy waiting

13/05/12                       GROUP - F                               7
Sleep and Wakeup: Producer Consumer Problem
Function performed by Producer :
Repeat forever-------->
. item=produce item()
. while(count=max)      sleep()
. insert_item(item)
. count=count+1
. if count=1) then wakeup consumer)
Function produced by Consumer :
repeat forever--------------->
. while(count=0) sleep();
. item=remove item()
. Count-count-1
. if count=max-1) then wakeup producer)
. consume(item)
DRAWBACK : Both may sleep forever.
                                           SOLUTION: USE OF WAKEUP WAITING BIT
 13/05/12                                 GROUP - F                          8
Semaphores: Producer Consumer Problem

Semaphore
     An integer to keep count of wakeups saved for future use

Down (semaphore)
• If value > 0, Decrement it and continue (one stored wakeup is
used)
• If value = 0, Process is put to sleep without completing Down

Up (semaphore)
     if one or more processes were sleeping on that semaphore (unable
to
     complete down operation), one of them is chosen by the system at

     random and allowed to complete its Down

13/05/12                           GROUP - F                            9
Semaphores: Producer Consumer Problem
Function performed by producer:
Repeat forever------>
     Generate something to put in buffer
     Perform DOWN operation on empty count;
     Enter critical region
     Put new item in buffer
     Leave critical region
     Perform UP on full counts
Function performed by consumer :
repeat forever------->
      Perform DOWN operation on full.
      Enter critical section.
      Take item from buffer
      Leave critical region
      Perform UP operation on empty counts
                                          CONCLUSION: NO BUSY WAITING
13/05/12                             GROUP - F                          10
Readers and writers problem


           This model deals with the access to database.


    Constraints:
Allows multiple processes to read database simultaneously.

Doesn't allow any other process to access database when a
   process writes into the database .




05/13/12                          GROUP I                    11
Application of semaphore in readers and writers
problem


    Function performed by reader :

    Enter into critical section and increase reader_counter, and check if
    it becomes 1 if it is perform down operation on a semaphore db.

    Exit the critical section .

    Read database

    Enter into critical section and decrease reader_counter by 1 .

    if it becomes 0 perform UP operation on semaphore db. Exit the
    critical section.

    Functions performed by writer

    Perform DOWN on semaphore db .

    Write into database.

    Perform UP operation on db.

    Exit .

05/13/12                           GROUP I                              12
Dining Philosophers problem in IPC
A problem used for modeling processes competing for access to limited
    number of resources .
General incident:
For each philosopher
-> take_fork(left)
-> take_fork(right)
->eat()
-> put_fork(left)
-> put_fork(right)
Problem : Occurrence of DEADLOCK
Solution : Application of SEMAPHORE



13/05/12                          GROUP - F                             13
Application of Semaphore in Dining Philosophers
problem

        For each philosopher(i)
->take_fork(i)
   ...enter critical region
   ...set semaphore state[i]=hungry
   ...test whether left or right neighbour is in eating state ,
        If not then state[i]=eating , perform UP on semaphore ph(i)
   ...exit critical region
   ... perform DOWN operation on semaphore ph(i)

->eat()
->put_fork(i)
   ....enter critical region
   .... state[i]=thinking
                           RESULT IS NO DEADLOCK , NO STARVATION
13/05/12                                 GROUP - F                    14
Message Passing
 buffer size=N
 Function performed by producer
 while(TRUE)
 item=produce item()                          NO SHARED MEMORY IS USED

 receive(consumer,&m)
 build_message(&m,item)
 send(consumer,&m)
 End
 Function performed by consumer
 send N empty slots
 while (TRUE)
 receive_message(producer,&m)
 item=extract_item(&m)
 send(producer,&m)
 consume(item)
 end

13/05/12                          GROUP - F                              15
REFERENCES

   OPERATING SYSTEM (Andrew S. Tanenbaum)

  DISTRIBUTED OPERATING SYSTEM
( P.K.SINHA)




05/13/12              GROUP I                16
05/13/12   GROUP I   17

Contenu connexe

Similaire à Ipc

5 process synchronization
5 process synchronization5 process synchronization
5 process synchronizationBaliThorat1
 
Improving the ZFS Userland-Kernel API with Channel Programs - BSDCAN 2017 - M...
Improving the ZFS Userland-Kernel API with Channel Programs - BSDCAN 2017 - M...Improving the ZFS Userland-Kernel API with Channel Programs - BSDCAN 2017 - M...
Improving the ZFS Userland-Kernel API with Channel Programs - BSDCAN 2017 - M...Matthew Ahrens
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Toolsguest05c09d
 
Microsoft kafka load imbalance
Microsoft   kafka load imbalanceMicrosoft   kafka load imbalance
Microsoft kafka load imbalanceNitin Kumar
 
XML Parsing with Map Reduce
XML Parsing with Map ReduceXML Parsing with Map Reduce
XML Parsing with Map ReduceEdureka!
 
Rein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4jRein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4jRazorsight
 
Operating Systems: Revision
Operating Systems: RevisionOperating Systems: Revision
Operating Systems: RevisionDamian T. Gordon
 
Java Hates Linux. Deal With It.
Java Hates Linux.  Deal With It.Java Hates Linux.  Deal With It.
Java Hates Linux. Deal With It.Greg Banks
 
360|Flex Greenthreading In Flex
360|Flex Greenthreading In Flex360|Flex Greenthreading In Flex
360|Flex Greenthreading In FlexHuyen Tue Dao
 
Oracle Release 12 E-Business Suite Patching Best Practices
Oracle Release 12 E-Business Suite Patching Best PracticesOracle Release 12 E-Business Suite Patching Best Practices
Oracle Release 12 E-Business Suite Patching Best PracticesScott Jenner
 
Set model and page fault.44
Set model and page fault.44Set model and page fault.44
Set model and page fault.44myrajendra
 
Introduction to Hadoop part 2
Introduction to Hadoop part 2Introduction to Hadoop part 2
Introduction to Hadoop part 2Giovanna Roda
 
The Pensions Trust - VM Backup Experiences
The Pensions Trust - VM Backup ExperiencesThe Pensions Trust - VM Backup Experiences
The Pensions Trust - VM Backup Experiencesglbsolutions
 
Cloudera Impala Internals
Cloudera Impala InternalsCloudera Impala Internals
Cloudera Impala InternalsDavid Groozman
 
Apache Flink Worst Practices
Apache Flink Worst PracticesApache Flink Worst Practices
Apache Flink Worst PracticesKonstantin Knauf
 
2007-05-23 Cecchet_PGCon2007.ppt
2007-05-23 Cecchet_PGCon2007.ppt2007-05-23 Cecchet_PGCon2007.ppt
2007-05-23 Cecchet_PGCon2007.pptnadirpervez2
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internalsKostas Tzoumas
 

Similaire à Ipc (20)

5 process synchronization
5 process synchronization5 process synchronization
5 process synchronization
 
Improving the ZFS Userland-Kernel API with Channel Programs - BSDCAN 2017 - M...
Improving the ZFS Userland-Kernel API with Channel Programs - BSDCAN 2017 - M...Improving the ZFS Userland-Kernel API with Channel Programs - BSDCAN 2017 - M...
Improving the ZFS Userland-Kernel API with Channel Programs - BSDCAN 2017 - M...
 
Rails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & ToolsRails Application Optimization Techniques & Tools
Rails Application Optimization Techniques & Tools
 
Microsoft kafka load imbalance
Microsoft   kafka load imbalanceMicrosoft   kafka load imbalance
Microsoft kafka load imbalance
 
XML Parsing with Map Reduce
XML Parsing with Map ReduceXML Parsing with Map Reduce
XML Parsing with Map Reduce
 
Rein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4jRein_in_the_ability_of_log4j
Rein_in_the_ability_of_log4j
 
Operating Systems: Revision
Operating Systems: RevisionOperating Systems: Revision
Operating Systems: Revision
 
Java Hates Linux. Deal With It.
Java Hates Linux.  Deal With It.Java Hates Linux.  Deal With It.
Java Hates Linux. Deal With It.
 
360|Flex Greenthreading In Flex
360|Flex Greenthreading In Flex360|Flex Greenthreading In Flex
360|Flex Greenthreading In Flex
 
Oracle Release 12 E-Business Suite Patching Best Practices
Oracle Release 12 E-Business Suite Patching Best PracticesOracle Release 12 E-Business Suite Patching Best Practices
Oracle Release 12 E-Business Suite Patching Best Practices
 
CLIPS Basic Student Guide
CLIPS Basic Student GuideCLIPS Basic Student Guide
CLIPS Basic Student Guide
 
Set model and page fault.44
Set model and page fault.44Set model and page fault.44
Set model and page fault.44
 
Introduction to Hadoop part 2
Introduction to Hadoop part 2Introduction to Hadoop part 2
Introduction to Hadoop part 2
 
Ipc feb4
Ipc feb4Ipc feb4
Ipc feb4
 
The Pensions Trust - VM Backup Experiences
The Pensions Trust - VM Backup ExperiencesThe Pensions Trust - VM Backup Experiences
The Pensions Trust - VM Backup Experiences
 
Being agile with modern Java
Being agile with modern JavaBeing agile with modern Java
Being agile with modern Java
 
Cloudera Impala Internals
Cloudera Impala InternalsCloudera Impala Internals
Cloudera Impala Internals
 
Apache Flink Worst Practices
Apache Flink Worst PracticesApache Flink Worst Practices
Apache Flink Worst Practices
 
2007-05-23 Cecchet_PGCon2007.ppt
2007-05-23 Cecchet_PGCon2007.ppt2007-05-23 Cecchet_PGCon2007.ppt
2007-05-23 Cecchet_PGCon2007.ppt
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internals
 

Dernier

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Dernier (20)

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 

Ipc

  • 1. INTERPROCESS COMMUNICATION (M.SC Computer Science) 13/05/12 GROUP - F 1
  • 2. OUTLINE  WHAT IS IPC  ABOUT RACE CONDITION  CRITICAL REGIONS  MANAGE RACE CONDITION  DINING PHILOSOPHER PROBLEM  MESSAGE PASSING 05/13/12 GROUP I 2
  • 3. What is IPC ?  Processes frequently need to communicate with other processes.  Generally shared memory is used to establish the connection among processes.  This memory must be shared carefully to avoid inconsistency. 13/05/12 GROUP - F 3
  • 4. IPC: Race Condition Spooler directory . . Race condition :- out= 4 4 abc The situation where two or more processes are Process A 5 prog.c reading or writing some in =6 shared data is called race 6 condition. Process B . . . Two processes want to access shared memory at same time 13/05/12 GROUP - F 4
  • 5. IPC: Critical Regions Critical Region/ Critical Section The part of the program where the shared memory is accessed is called the critical region. conditions to provide mutual exclusion  No two processes will be in critical region simultaneously.  No process running outside its critical region may block another process.  No process must wait forever to enter its critical region. 13/05/12 GROUP - F 5
  • 6. How to Manage Race Condition ?  Mutual Exclusion with Busy Waiting  Strict Alternation  Mutual Exclusion without Busy Waiting  Sleep and wakeup  Semaphore  Message Passing 13/05/12 GROUP - F 6
  • 7. STRICT ALTERNATION while(TRUE) while(TRUE) { { while(turn!=0) /* loop /; while(turn!=1) /* loop */ critical_region(); critical_region(); turn=1; turn=0; noncritical_region(); noncritical_region(); } } Process A Process B DRAWBACK: wastage of CPU time by Busy waiting 13/05/12 GROUP - F 7
  • 8. Sleep and Wakeup: Producer Consumer Problem Function performed by Producer : Repeat forever--------> . item=produce item() . while(count=max) sleep() . insert_item(item) . count=count+1 . if count=1) then wakeup consumer) Function produced by Consumer : repeat forever---------------> . while(count=0) sleep(); . item=remove item() . Count-count-1 . if count=max-1) then wakeup producer) . consume(item) DRAWBACK : Both may sleep forever. SOLUTION: USE OF WAKEUP WAITING BIT 13/05/12 GROUP - F 8
  • 9. Semaphores: Producer Consumer Problem Semaphore An integer to keep count of wakeups saved for future use Down (semaphore) • If value > 0, Decrement it and continue (one stored wakeup is used) • If value = 0, Process is put to sleep without completing Down Up (semaphore) if one or more processes were sleeping on that semaphore (unable to complete down operation), one of them is chosen by the system at random and allowed to complete its Down 13/05/12 GROUP - F 9
  • 10. Semaphores: Producer Consumer Problem Function performed by producer: Repeat forever------>  Generate something to put in buffer  Perform DOWN operation on empty count;  Enter critical region  Put new item in buffer  Leave critical region  Perform UP on full counts Function performed by consumer : repeat forever------->  Perform DOWN operation on full.  Enter critical section.  Take item from buffer  Leave critical region  Perform UP operation on empty counts CONCLUSION: NO BUSY WAITING 13/05/12 GROUP - F 10
  • 11. Readers and writers problem  This model deals with the access to database.  Constraints: Allows multiple processes to read database simultaneously. Doesn't allow any other process to access database when a process writes into the database . 05/13/12 GROUP I 11
  • 12. Application of semaphore in readers and writers problem  Function performed by reader :  Enter into critical section and increase reader_counter, and check if it becomes 1 if it is perform down operation on a semaphore db.  Exit the critical section .  Read database  Enter into critical section and decrease reader_counter by 1 .  if it becomes 0 perform UP operation on semaphore db. Exit the critical section.  Functions performed by writer  Perform DOWN on semaphore db .  Write into database.  Perform UP operation on db.  Exit . 05/13/12 GROUP I 12
  • 13. Dining Philosophers problem in IPC A problem used for modeling processes competing for access to limited number of resources . General incident: For each philosopher -> take_fork(left) -> take_fork(right) ->eat() -> put_fork(left) -> put_fork(right) Problem : Occurrence of DEADLOCK Solution : Application of SEMAPHORE 13/05/12 GROUP - F 13
  • 14. Application of Semaphore in Dining Philosophers problem  For each philosopher(i) ->take_fork(i) ...enter critical region ...set semaphore state[i]=hungry ...test whether left or right neighbour is in eating state , If not then state[i]=eating , perform UP on semaphore ph(i) ...exit critical region ... perform DOWN operation on semaphore ph(i) ->eat() ->put_fork(i) ....enter critical region .... state[i]=thinking RESULT IS NO DEADLOCK , NO STARVATION 13/05/12 GROUP - F 14
  • 15. Message Passing buffer size=N Function performed by producer while(TRUE) item=produce item() NO SHARED MEMORY IS USED receive(consumer,&m) build_message(&m,item) send(consumer,&m) End Function performed by consumer send N empty slots while (TRUE) receive_message(producer,&m) item=extract_item(&m) send(producer,&m) consume(item) end 13/05/12 GROUP - F 15
  • 16. REFERENCES  OPERATING SYSTEM (Andrew S. Tanenbaum)  DISTRIBUTED OPERATING SYSTEM ( P.K.SINHA) 05/13/12 GROUP I 16
  • 17. 05/13/12 GROUP I 17