Presentation is loading. Please wait.

Presentation is loading. Please wait.

TANNENBAUM SECTION 2.3 INTERPROCESS COMMUNICATION4 OPERATING SYSTEMS.

Similar presentations


Presentation on theme: "TANNENBAUM SECTION 2.3 INTERPROCESS COMMUNICATION4 OPERATING SYSTEMS."— Presentation transcript:

1 TANNENBAUM SECTION 2.3 INTERPROCESS COMMUNICATION4 OPERATING SYSTEMS

2 MESSAGE PASSING Both Peterson and Semaphores require shared memory These solutions are not possible in a distributed system where each machine has only local memory

3 TWO MESSAGING PASSING PRIMITIVES //send a message to a destination send(dest, &msg) //receive a message from a destination receive(source, &msg

4 SYNCHRONOUS (NON-BUFFERED) MESSAGE PASSING sender sends Blocks until it gets a msg that it has been received Receiver blocks until sender is done Example: buffer can hold a single message Receiver tries to receive when buffer is empy  block Sender tries to send when buffer is full  block Implemented in unix with pipes having a single position

5 SYNCHRONOUS MODEL void producer(void) { int item; while(1) { item = make_item(); send(consumer, &item) } void consumer(void) { int item; while(1) { receive(producer, &item); use(item); }

6 ASYNCHRONOUS (BUFFERED) MESSAGE PASSING produces works until buffer is full consumer works until buffer is empty Example Producer sends consumer N empty messages Producer stores its item in an empty message and sends back a full one Produces blocks when it runs out of empty messages Consumer blocks when all available messages are empty Messages sent but not yet received are buffered by the O/S

7 ASYNCHRONOUS MODEL #define N 100 void producer(void) { int item; message m; while(1) { item = make_item(); receive(consumer, &m); fill_msg(item,&m); send(consumer, &m) } void consumer(void) { int item, i; message m; for (i = 0; i < N; i++) send(producer, &m); while(1) { receive(producer, &item); extract_msg(&item, &msg); send(producer, &m); use(item); }

8 PIPES a pipe is a direct i/o channel between processes write end read end nreB^eht^leeF P C

9 TWO PIPES REQUIRED TO IMPLEMENT PRODUCE/CONSUMER a pipe is a direct i/o channel between processes producer pipe P C consumer pipe

10 SYNTAX char buf[50]; int file_des[2]; pipe(file_des); where file_des[0] is the read end file_des[1] i sthe write end int read(int, char*, int); int status = read(fildes[0], buf, 50); int write(int, char*, int); int status = read(fildes[1], buf, 50); See sample program

11 SCHEDULING Linux prefers short interactive processes Time ticks every 10 ms


Download ppt "TANNENBAUM SECTION 2.3 INTERPROCESS COMMUNICATION4 OPERATING SYSTEMS."

Similar presentations


Ads by Google