Docsity

Interprocess Communication: Message Passing and UNIX Pipes, Study notes of Operating Systems

Toggle sidebar
bg1
New Topic: Interprocess Communication
•Shared data structures offer only an unstructured method of
IPC
•Alternative: processes can communicate by exchanging
ā€œmessagesā€
ā€“ā€œmessageā€ can be simply a data value
–no need for shared variables (or their headaches)
•Analogy: global variables vs. parameter passing to
subroutines in a high-level language
•Basic operations: send(message) & receive(message)
Basic Message-Passing Issues
•How are communication links established?
•Any reliability measures?
•How many processes can be associated with a link?
•How many messages can be buffered at once in the link?
•What are message sizes?
•How are communication links closed, or deleted?
1
pf3
pf4
pf5

Partial preview of the text

Download Interprocess Communication: Message Passing and UNIX Pipes and more Study notes Operating Systems in PDF only on Docsity!

New Topic: Interprocess Communication

• Shared data structures offer only an unstructured method of

IPC

• Alternative: processes can communicate by exchanging

ā€œmessagesā€

– ā€œmessageā€ can be simply a data value

– no need for shared variables (or their headaches)

• Analogy: global variables vs. parameter passing to

subroutines in a high-level language

• Basic operations: send(message) & receive(message)

Basic Message-Passing Issues

• How are communication links established?

• Any reliability measures?

• How many processes can be associated with a link?

• How many messages can be buffered at once in the link?

• What are message sizes?

• How are communication links closed, or deleted?

Message-Passing Varieties

• Synchronous (Blocking)

• Asynchronous (Non-Blocking)

• Symmetric Direct

• Asymmetric Direct

• Indirect IPC (Mailboxes)

Synchronous vs. Asynchronous

• Synchronous:

– Sender’s processing progress is blocked until an ACK is received from

receiver.

– Receiver’s processing progress is blocked until it receives some message

from sender.

• Asynchronous:

– Sender does not wait for ACK from receiver

– Receiver simply continues processing if no message has been sent

Indirect IPC

• Messages are sent from a sender to a mailbox (buffer),

where they are held until a receiver reads one.

– you don’t need to know a process’ name to communicate, only need to

know MAILBOX where it gets its messages!

• Mailbox operations:

– send

– receive

– create

– destroy

• Mailbox lifetimes:

– ā€œImmortal:ā€ some owned by system, having a fixed name, and are never

destroyed

– others might be dynamically created, named, and destroyed by any process

Case Study: IPC in UNIX(tm)

• Processes in UNIX communicate via PIPES

• Pipes have a ā€œread endā€ and a ā€œwrite endā€

P1 Pipe_ID P

write(pipe_id, message, nbytes) (^) read(pipe_id,buffer,xbytes)

Pipes are created via the ā€œpipe()ā€ system call

int p[2]; ... ... pipe(p); / creates a pipe and returns ID of read-end in p[0] and ID of write-end in p[1] /

Pipe creation

Pipes are created via the ā€œpipe()ā€ system call

int p[2]; ... ... pipe(p); / creates a pipe and returns ID of read-end in p[0] and ID of write-end in p[1] /

When a process creates a pipe, it is given EXCLUSIVE

access to the pipe’s read and write ends.

- all this does is let process want ā€œtalk to itselfā€

- how might this be useful?

File Descriptors & Pipes in UNIX

• Feature: file system, device i/o and IPC are integrated in

UNIX!

• Each process has a list (where?) of (typically 16) file (object)

descriptors

• Each open descriptor is associated with a device, file, or

pipe

• ā€œwrite(, , )ā€

– outputs the buffer to the file, pipe, or device associated with the

Pipes, Parents, and Progeny in Unix

p[1] p[0]

Step 2: P0 creates P1 and P2, which inherit pipes

At this time, any of them can read/write from/to the pipe.

P

P

P

Pipes, Parents, and Progeny in Unix

P

p[1] p[0]

P

Step 3: all processes close pipe ends which they will not (should not) be accessing:

close(p[0]); close(p[1]);

close(p[1]);

close(p[0])

P

P

P