Ipcs 3
Ipcs 3
Spring 2018
Kernel Kernel
Process A Process A
Process B Process B
Available Available
Memory Memory
Process A Process A
M
Process B Process B
Available Available
Memory Memory
Process A Process A
M
Process B Process B
Available Available
Memory Memory
Process A Process A
M
Process B Process B
M
Available Available
Memory Memory
Process A Process A
M
Process B Process B
M
Available Available
Memory Memory
Shared Memory
Process A Process A
M
Process B Process B
M
Available Available
Memory Memory
Shared Memory
Synchronous = Blocking
Synchronous send: Block until the message is received
Synchronous recv: Block until a message is available
When both send and receive are blocking, the operation is a
rendez-vous
Synchronous = Blocking
Synchronous send: Block until the message is received
Synchronous recv: Block until a message is available
When both send and receive are blocking, the operation is a
rendez-vous
Asynchronous = Non-Blocking
Non-blocking send: Send and continue
Usually comes with the option to check the status later (Was
the message received?)
Non-blocking receive: e.g. Read any number of bytes (possibly
0) or any message (possibly the empty one, or null)
Process A Process A
M
Process B Process B
M
Available Available
Memory Memory
Shared Memory
Implementation in C
SystemV Implementation:
Creation/Request for a new shared memory segment:
id = shmget(IPC PRIVATE, size, IPC R | IPC W)
Attaching a process to the id shared memory segment:
shmsAddress = shmat(id, NULL, 0);
Detach the memory segment:
shmdt(shmsAddress);
Release control of the shared memory segment:
shmctl(idm, IPC RMID, NULL);
When the process is attached:
“sending”: sprintf(shmsAddress, "Hello, World!");
“receiving”: sscanf(shmsAddress, "%s", &message);
Let’s look at the posix shm example.c example
One of the most ancient, yet simple, useful, and powerful IPC
mechanism provided by OSes is typically called pipes
One of the most ancient, yet simple, useful, and powerful IPC
mechanism provided by OSes is typically called pipes
This program will run ls -la and write its output to file
/tmp/stuff!
Let’s look at output redirect example1.c
This program will run ls -la and write its output to file
/tmp/stuff!
Let’s look at output redirect example2.c
// Get lines of output from the pipe, which is just a FILE ∗, until EOF is reached
char buffer[2048];
while (fgets(buffer, 2048, pipe)) {
fprintf(stderr,"LINE: %s", buffer);
}
Textbook readings:
About Pipes (Section 5.4)
About Client-Servers and RPCs (Section 47.5)