Sie sind auf Seite 1von 2

Case study: IPC in Linux

Interprocess Communication UNIX provides a rich environment for processes to communicate with each other. Communication may be just a matter of ettin! another process "now that some event has occurred# or it may invo ve transferrin! data from one process to another. Synchronization and Signals $he standard UNIX mechanism for informin! a process that an event has occurred is the si!na . %i!na s can be sent from any process to any other process# with restrictions on si!na s sent to processes owned by another user. &owever# a imited number of si!na s are avai ab e# and they cannot carry information: 'n y the fact that a si!na occurred is avai ab e to a process. %i!na s are not !enerated on y by processes. $he "erne a so !enerates si!na s interna y( for examp e# it can send a si!na to a server process when data arrive on a networ" channe # to a parent process when a chi d terminates# or to a waitin! process when a timer expires. Interna y# the Linux "erne does not use si!na s to communicate with processes runnin! in "erne mode. If a "erne )mode process is expectin! an event to occur# it wi not norma y use si!na s to receive notification of that event. *ather# communication about incomin! asynchronous events within the "erne is performed throu!h the use of schedu in! states and wait)+ueue structures. $hese mechanisms a ow "erne )mode processes to inform one another about re evant events# and they a so a ow events to be !enerated by device drivers or by the networ"in! system. ,henever a process wants to wait for some event to comp ete# it p aces itse f on a wait queue associated with that event and te s the schedu er that it is no on!er e i!ib e for execution. 'nce the event has comp eted# it wi wa"e up every process on the wait +ueue. $his procedure a ows mu tip e processes to wait for a sin! e event. - thou!h si!na s have a ways been the main mechanism for communicatin! asynchronous events amon! processes# - process can wait on a semaphore as easi y as it can wait for a si!na # but semaphores have two advanta!es: Lar!e numbers of semaphores can be shared amon! mu tip e independent processes# and operations on mu tip e semaphores can be performed

atomica y. Interna y# the standard Linux wait +ueue mechanism synchroni.es processes that are communicatin! with semaphores. Passing of Data among Processes Linux offers severa mechanisms for passin! data amon! processes. $he standard UNIX pipe mechanism a ows a chi d process to inherit a communication channe from its parent( data written to one end of the pipe can be read at the other. Under Linux# pipes appear as just another type of inode to virtua )fi esystem software# and each pipe has a pair of wait +ueues to synchroni.e the reader and writer. UNIX a so defines a set of networ"in! faci ities that can send streams of data to both oca and remote processes.

Das könnte Ihnen auch gefallen