pipes use an implicit addressing mechanism that limits their use to
communication between
related
processes, typically a child process and its
parent
•
a
pipe()
system call creates a pipe and returns two descriptors, one for each
end of the pipe
–
for a simplex pipe, one descriptor is for reading, the other is for writing
–
for a duplex pipe, both descriptors can be used for reading and writing
CS350
Operating Systems
Fall 2007
145

Interprocess Communication
27
One-way Child/Parent Communication Using a Simplex Pipe
int fd[2];
char m[] = "message for parent";
char y[100];
pipe(fd); // create pipe
pid = fork(); // create child process
if (pid == 0)
{
// child executes this
close(fd[0]); // close read end of pipe
write(fd[1],m,19);
...
}
else
{
// parent executes this
close(fd[1]); // close write end of pipe
read(fd[0],y,100);
...
}
CS350
Operating Systems
Fall 2007
Interprocess Communication
28
Illustration of Example (after
pipe()
)
parent process
CS350
Operating Systems
Fall 2007
146

Interprocess Communication
29
Illustration of Example (after
fork()
)
parent process
child process
CS350
Operating Systems
Fall 2007
Interprocess Communication
30
Illustration of Example (after
close()
)
parent process
child process
CS350
Operating Systems
Fall 2007
147

Interprocess Communication
31
Examples of Other Interprocess Communication Mechanisms
named pipe:
•
similar to pipes, but with an associated name (usually a file name)
•
name allows arbitrary processes to communicate by opening the same
named pipe
•
must be explicitly deleted, unlike an unnamed pipe
message queue:
•
like a named pipe, except that there are message boundaries
•
msgsend
call sends a message into the queue,
msgrecv
call receives the
next message from the queue
CS350
Operating Systems
Fall 2007
Interprocess Communication
32
Implementing IPC
•
application processes use descriptors (identifiers) provided by the kernel to
refer to specific sockets and pipes, as well as files and other objects
•
kernel
descriptor tables
(or other similar mechanism) are used to associate
descriptors with kernel data structures that implement IPC objects
•
kernel provides bounded buffer space for data that has been sent using an IPC
mechanism, but that has not yet been received
–
for IPC objects, like pipes, buffering is usually on a per object basis
–
IPC end points, like sockets, buffering is associated with each endpoint
P1
P2
system call
interface
system call
interface
buffer
operating system
CS350
Operating Systems
Fall 2007
148

Interprocess Communication
33
Network Interprocess Communication
•
some sockets can be used to connect processes that are running on different
machine
•
the kernel:
–
controls access to network interfaces
–
multiplexes socket connections across the network
P2
P3
P1
network interface
P2
P3
P1
network interface
network
operating
system
operating
system
CS350
Operating Systems
Fall 2007
Interprocess Communication
34
Networking Reference Models
•
ISO/OSI Reference
Model
7
Application Layer
6
Presentation Layer
5
Session Layer
4
Transport Layer
3
Network Layer
2
Data Link Layer
1
Physical Layer
•
Internet Model
–
layers 1-4 and 7
Layer 1
Layer 1
Layer N
Layer N+1
Layer N


You've reached the end of your free preview.
Want to read all 164 pages?
- '19
- Virtual memory, Computer multitasking, Context switch