Ipc
Upcoming SlideShare
Loading in...5
×
 

Ipc

on

  • 376 views

Inter Process Communication

Inter Process Communication

Statistics

Views

Total Views
376
Views on SlideShare
376
Embed Views
0

Actions

Likes
0
Downloads
42
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Ipc Ipc Presentation Transcript

  • 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 PASSING05/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 View slide
  • 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 time13/05/12 GROUP - F 4 View slide
  • IPC: Critical RegionsCritical 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 Passing13/05/12 GROUP - F 6
  • STRICT ALTERNATIONwhile(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 waiting13/05/12 GROUP - F 7
  • Sleep and Wakeup: Producer Consumer ProblemFunction 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 ProblemSemaphore An integer to keep count of wakeups saved for future useDown (semaphore)• If value > 0, Decrement it and continue (one stored wakeup isused)• If value = 0, Process is put to sleep without completing DownUp (semaphore) if one or more processes were sleeping on that semaphore (unableto complete down operation), one of them is chosen by the system at random and allowed to complete its Down13/05/12 GROUP - F 9
  • Semaphores: Producer Consumer ProblemFunction 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 countsFunction 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 WAITING13/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.Doesnt 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 writersproblem 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 IPCA 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 DEADLOCKSolution : Application of SEMAPHORE13/05/12 GROUP - F 13
  • Application of Semaphore in Dining Philosophersproblem 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 STARVATION13/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) end13/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