SlideShare a Scribd company logo
1 of 87
Download to read offline
Processes (Part II)
Amir H. Payberah
amir@sics.se
Amirkabir University of Technology
(Tehran Polytechnic)
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 1 / 58
Inter-Process Communication
(IPC)
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 2 / 58
Cooperating Processes
Processes within a system may be independent or cooperating.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
Cooperating Processes
Processes within a system may be independent or cooperating.
• Independent process cannot affect or be affected by the execution
of another process.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
Cooperating Processes
Processes within a system may be independent or cooperating.
• Independent process cannot affect or be affected by the execution
of another process.
• Cooperating process can affect or be affected by other processes.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
Cooperating Processes
Processes within a system may be independent or cooperating.
• Independent process cannot affect or be affected by the execution
of another process.
• Cooperating process can affect or be affected by other processes.
Reasons for cooperating processes: information sharing, computa-
tion speedup, ...
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
Cooperating Processes
Processes within a system may be independent or cooperating.
• Independent process cannot affect or be affected by the execution
of another process.
• Cooperating process can affect or be affected by other processes.
Reasons for cooperating processes: information sharing, computa-
tion speedup, ...
Producer-Consumer model: producer process produces information
that is consumed by a consumer process.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
Inter-Process Communication
Cooperating processes require an interprocess communication (IPC)
mechanism that will allow them to exchange data and information.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 4 / 58
Inter-Process Communication
Cooperating processes require an interprocess communication (IPC)
mechanism that will allow them to exchange data and information.
Two models of IPC
• Shared memory
• Message passing
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 4 / 58
Shared Memory
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 5 / 58
Shared Memory (1/3)
An area of memory shared among the processes that wish to com-
municate.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 6 / 58
Shared Memory (2/3)
It is resides in the address space of the process creating the shared-
memory segment.
Other processes must attach it to their address space for communi-
cation.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 7 / 58
Shared Memory (3/3)
But, OS prevents one process from accessing another process’s
memory.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 8 / 58
Shared Memory (3/3)
But, OS prevents one process from accessing another process’s
memory.
Shared memory requires that two or more processes agree to remove
this restriction.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 8 / 58
Shared Memory (3/3)
But, OS prevents one process from accessing another process’s
memory.
Shared memory requires that two or more processes agree to remove
this restriction.
The communication is under the control of the users processes not
the OS.
• Synchronization
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 8 / 58
Shared Memory - Producer-Consumer Model (1/3)
Defining the buffer.
• Unbounded buffer: no practical limit on the size of the buffer.
• Bounded buffer: a fixed buffer size.
#define BUFFER_SIZE 10
typedef struct {
...
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 9 / 58
Shared Memory - Producer-Consumer Model (2/3)
Producer
item next_produced;
while (true) {
// produce an item in next produced
while (((in + 1) % BUFFER_SIZE) == out) {
// do nothing
}
buffer[in] = next_produced;
in = (in + 1) % BUFFER_SIZE;
}
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 10 / 58
Shared Memory - Producer-Consumer Model (3/3)
Consumer
item next_consumed;
while (true) {
while (in == out) {
// do nothing
}
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
// consume the item in next consumed
}
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 11 / 58
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 12 / 58
A Taxonomy of Linux IPC Facilities
[Michael Kerrisk, The Linux Programming Interface, No Starch Press, 2010]
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 13 / 58
System V vs. POSIX IPC
System V (System Five): one of the first commercial versions of the
Unix OS.
POSIX (Portable Operating System Interface): a family of standards
for maintaining compatibility between OSs.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 14 / 58
System V vs. POSIX IPC
System V (System Five): one of the first commercial versions of the
Unix OS.
POSIX (Portable Operating System Interface): a family of standards
for maintaining compatibility between OSs.
Both have the same basic IPC tools, but they offer a slightly different
interfaces to those tools.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 14 / 58
System V vs. POSIX IPC
System V (System Five): one of the first commercial versions of the
Unix OS.
POSIX (Portable Operating System Interface): a family of standards
for maintaining compatibility between OSs.
Both have the same basic IPC tools, but they offer a slightly different
interfaces to those tools.
System V is fully supported on all Linux kernels.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 14 / 58
POSIX Shared Memory
To use a POSIX shared memory object, we perform two steps:
1 Use the shm open() function to open an object with a specified
name.
2 Pass the file descriptor obtained in the previous step in a call to
mmap() that maps the shared memory object into the process’s virtual
address space.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 15 / 58
Creating Shared Memory Objects
shm open() creates and opens a new shared memory object or opens
an existing object.
mmap() creates a new mapping in the virtual address space of the
calling process.
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
int shm_open(const char *name, int oflag, mode_t mode);
void *mmap(void *addr, size_t length, int prot, int flags, int fd,
off_t offset);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 16 / 58
Removing Shared Memory Objects
shm unlink() removes a shared memory object.
#include <sys/mman.h>
int shm_unlink(const char *name);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 17 / 58
Producer-Consumer via Shared Memory (1/2)
Producer
int SIZE = 4096;
char *my_shm = "/tmp/myshm";
char *write_msg = "hello";
char *addr;
int fd;
// create the shared memory object
fd = shm_open(my_shm, O_CREATE | O_RDWR, 0666);
// configuare the size of the shared memory object
ftruncate(fd, SIZE);
// memory map to the shared memory object
addr = mmap(NULL, SIZE, PROT_WRITE, MAP_SHARED, fd, 0);
// write to the shared object
sprintf(addr, "%s", write_msg);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 18 / 58
Producer-Consumer via Shared Memory (2/2)
Consumer
int SIZE = 4096;
char *my_shm = "/tmp/myshm";
char *addr;
int fd;
// open the shared memory object
fd = shm_open(my_shm, O_RDONLY, 0666);
// memory map to the shared memory object
addr = mmap(NULL, SIZE, PROT_READ, MAP_SHARED, fd, 0);
// read from to the shared object
printf("%s", (char *)addr);
// remove the shared memory object
shm_unlink("my_shm");
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 19 / 58
Message Passing
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 20 / 58
Message Passing (1/2)
Processes communicate with each other without resorting to shared
variables.
Useful in a distributed environment: processes on different comput-
ers.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 21 / 58
Message Passing (2/2)
Two operations: send(message) and receive(message).
If processes p and q wish to communicate, they need to:
• Establish a communication link between them.
• Exchange messages via send and receive.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 22 / 58
Message Passing (2/2)
Two operations: send(message) and receive(message).
If processes p and q wish to communicate, they need to:
• Establish a communication link between them.
• Exchange messages via send and receive.
Implementation of communication link:
• Physical links, e.g., shared memory, hardware bus, network
• Logical links
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 22 / 58
Logical Links
Naming: direct or indirect communication
Synchronization: synchronous or asynchronous communication
Buffering: automatic or explicit buffering
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 23 / 58
Naming (1/3)
With direct communication, processes must name each other ex-
plicitly:
• send(p, message): sends a message to process p.
• receive(q, message): receives a message from process q.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 24 / 58
Naming (1/3)
With direct communication, processes must name each other ex-
plicitly:
• send(p, message): sends a message to process p.
• receive(q, message): receives a message from process q.
Properties of communication link:
• A link is associated with exactly two processes.
• Between each pair of processes, there exists exactly one link.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 24 / 58
Naming (2/3)
With indirect communication the messages are sent to and received
from mailboxes or ports.
• send(A, message): sends a message to mailbox A.
• receive(A, message): receives a message from mailbox A.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 25 / 58
Naming (2/3)
With indirect communication the messages are sent to and received
from mailboxes or ports.
• send(A, message): sends a message to mailbox A.
• receive(A, message): receives a message from mailbox A.
Properties of communication link:
• A link is established only if processes share a common mailbox.
• A link may be associated with more than two processes.
• Each pair of processes may share several communication links.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 25 / 58
Naming (3/3)
Mailbox sharing
• p1, p2, and p3 share mailbox A.
• p1 sends; p2 and p3 receive.
• Who gets the message?
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 26 / 58
Naming (3/3)
Mailbox sharing
• p1, p2, and p3 share mailbox A.
• p1 sends; p2 and p3 receive.
• Who gets the message?
Solutions
• Allow a link to be associated with at most two processes.
• Allow only one process at a time to execute a receive operation.
• Allow the system to select arbitrarily the receiver. Sender is notified
who the receiver was.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 26 / 58
Synchronization (1/2)
Message passing may be either blocking or non-blocking.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 27 / 58
Synchronization (1/2)
Message passing may be either blocking or non-blocking.
Blocking is considered synchronous.
• Blocking send: the sender is blocked until the message is received.
• Blocking receive: the receiver is blocked until a message is available.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 27 / 58
Synchronization (1/2)
Message passing may be either blocking or non-blocking.
Blocking is considered synchronous.
• Blocking send: the sender is blocked until the message is received.
• Blocking receive: the receiver is blocked until a message is available.
Non-blocking is considered asynchronous.
• Non-blocking send: the sender sends the message and continue.
• Non-blocking receive: the receiver receives a valid message, or null
message.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 27 / 58
Synchronization (2/2)
Producer-consumer model
// producer
// message: next_produced;
while (true) {
// produce an item in next produced
send(next_produced);
}
// consumer
// message: next_consumed;
while (true) {
receive(next_consumed);
// consume the item in next consumed
}
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 28 / 58
Buffering
Queue of the messages attached to the link.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 29 / 58
Buffering
Queue of the messages attached to the link.
Implemented in one of three ways:
• Zero capacity: no messages are queued on a link. Sender must wait
for receiver.
• Bounded capacity: finite length of n messages Sender must wait if
link full.
• Unbounded capacity: infinite length. Sender never waits.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 29 / 58
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 30 / 58
A Taxonomy of Linux IPC Facilities
[Michael Kerrisk, The Linux Programming Interface, No Starch Press, 2010]
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 31 / 58
Data Message vs. Data Stream (1/2)
Message oriented protocols send data in distinct chunks or groups.
• The receiver of data can determine where one message ends and
another begins.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 32 / 58
Data Message vs. Data Stream (1/2)
Message oriented protocols send data in distinct chunks or groups.
• The receiver of data can determine where one message ends and
another begins.
Stream protocols send a continuous flow of data.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 32 / 58
Data Message vs. Data Stream (2/2)
Example with mobile phones: text messages would be a message
oriented protocol, and a phone call is stream oriented.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 33 / 58
Data Message vs. Data Stream (2/2)
Example with mobile phones: text messages would be a message
oriented protocol, and a phone call is stream oriented.
UDP is a message oriented protocol, and TCP is a stream oriented
protocol.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 33 / 58
Message Passing IPC Facilities
Data stream:
• Pipe
• FIFO (named pipe)
• Stream socket
Data message:
• Message queue
• Datagram socket
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 34 / 58
Pipe
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 35 / 58
Pipe
Pipes allow two processes to communicate in standard producer-
consumer fashion.
• The producer writes to the write-end, and the consumer reads from
the read-end.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 36 / 58
Pipe
Pipes allow two processes to communicate in standard producer-
consumer fashion.
• The producer writes to the write-end, and the consumer reads from
the read-end.
Pipes are unidirectional, allowing only one-way communication.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 36 / 58
Pipe
Pipes allow two processes to communicate in standard producer-
consumer fashion.
• The producer writes to the write-end, and the consumer reads from
the read-end.
Pipes are unidirectional, allowing only one-way communication.
Require parent-child relationship between communicating processes.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 36 / 58
Pipe
Pipes allow two processes to communicate in standard producer-
consumer fashion.
• The producer writes to the write-end, and the consumer reads from
the read-end.
Pipes are unidirectional, allowing only one-way communication.
Require parent-child relationship between communicating processes.
ls | wc -l
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 36 / 58
Creating a Pipe
The pipe() system call creates a new pipe.
It returns two open file descriptors in the array fd: fd[0] to read
from the pipe, and fd[1] to write to the pipe.
#include <unistd.h>
int pipe(int fd[2]);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 37 / 58
Parent-Child Communication Through a Pipe (1/2)
int BUFFER_SIZE = 25;
char write_msg[BUFFER_SIZE] = "hello";
char read_msg[BUFFER_SIZE];
int fd[2];
pipe(fd); // Create the pipe
switch (fork()) {
case -1: // fork error
break;
case 0: // Child
close(fd[1]); // Close unused write end
read(fd[0], read_msg, BUFFER_SIZE);
printf("read %s", read_msg);
break;
default: // Parent
close(fd[0]) // Close unused read end
write(fd[1], write_msg, strlen(write_msg) + 1);
break;
}
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 38 / 58
Parent-Child Communication Through a Pipe (2/2)
[Michael Kerrisk, The Linux Programming Interface, No Starch Press, 2010]
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 39 / 58
FIFO
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 40 / 58
FIFO (Named Pipe)
FIFO is similar to a pipe, but it has a name within the file system
and is opened in the same way as a regular file.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 41 / 58
FIFO (Named Pipe)
FIFO is similar to a pipe, but it has a name within the file system
and is opened in the same way as a regular file.
Communication is bidirectional.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 41 / 58
FIFO (Named Pipe)
FIFO is similar to a pipe, but it has a name within the file system
and is opened in the same way as a regular file.
Communication is bidirectional.
No parent-child relationship is necessary.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 41 / 58
FIFO (Named Pipe)
FIFO is similar to a pipe, but it has a name within the file system
and is opened in the same way as a regular file.
Communication is bidirectional.
No parent-child relationship is necessary.
Several processes can use a FIFO for communication.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 41 / 58
Creating a FIFO
The mkfifo() function creates a new FIFO.
#include <sys/stat.h>
int mkfifo(const char *pathname, mode_t mode);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 42 / 58
Producer-Consumer via FIFO (1/2)
Producer
char *my_fifo = "/tmp/myfifo";
char *write_msg = "hello";
int fd;
// Create the FIFO (named pipe)
mkfifo(my_fifo, 0666);
// Write "hello" to the FIFO
fd = open(my_fifo, O_WRONLY);
write(fd, write_msg, strlen(write_msg));
close(fd);
// Remove the FIFO
unlink(my_fifo);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 43 / 58
Producer-Consumer via FIFO (2/2)
Consumer
int MAX_SIZE = 100;
char *my_fifo = "/tmp/myfifo";
char buf[MAX_SIZE];
int fd;
// Open the FIFO
fd = open(my_fifo, O_RDONLY);
// Read the message from the FIFO
read(fd, buf, MAX_SIZE);
printf("Received: %sn", buf);
// Close the FIFO
close(fd);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 44 / 58
Message Queue
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 45 / 58
Message Queue
Message queues allows processes to exchange data in the form of
messages.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 46 / 58
Message Queue
Message queues allows processes to exchange data in the form of
messages.
In message queue the consumer receives whole messages, as written
by the producer.
• It is not possible to read part of a message and leave the remainder
in the queue, or to read multiple messages at a time.
• In pipes, the consumer can read an arbitrary number of bytes at a
time, irrespective of the size of data blocks written by the producer.
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 46 / 58
Creating a Message Queue
mq open() creates a new message queue or opens an existing queue.
#include <fcntl.h>
#include <sys/stat.h>
#include <mqueue.h>
mqd_t mq_open(const char *name, int oflag, ...
/* mode_t mode, struct mq_attr *attr */ );
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 47 / 58
Closing a Message Queue
mq close() closes the message queue descriptor mqdes.
#include <mqueue.h>
int mq_close(mqd_t mqdes);
mq unlink() removes the message queue identified by name.
#include <mqueue.h>
int mq_unlink(const char *name);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 48 / 58
Message Queue Attributes
Specifies attributes of a message queue.
struct mq_attr {
long mq_flags; // Message queue description flags
long mq_maxmsg; // Maximum number of messages on queue
long mq_msgsize; // Maximum message size (in bytes)
long mq_curmsgs; // Number of messages currently in queue
};
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 49 / 58
Retrieving and Modifying a Message Queue Attributes
mq getattr() returns a mq attr structure of the message queue.
#include <mqueue.h>
int mq_getattr(mqd_t mqdes, struct mq_attr *attr);
mq setattr() sets attributes of the message queue.
#include <mqueue.h>
int mq_setattr(mqd_t mqdes, const struct mq_attr *newattr,
struct mq_attr *oldattr);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 50 / 58
Sending and Receiving Messages
mq send() adds the message msg ptr to the message queue.
#include <mqueue.h>
int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
unsigned int msg_prio);
mq receive() removes the oldest message from the message queue.
#include <mqueue.h>
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
unsigned int *msg_prio);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 51 / 58
Message Notification
A way for asynchronous communications.
A process can request a notification of message arrival and then
performs other tasks until it is notified.
The mq notify() registers the calling process to receive a notifica-
tion when a message arrives on the empty queue.
#include <mqueue.h>
int mq_notify(mqd_t mqdes, const struct sigevent *notification);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 52 / 58
Linux Message Queue Pattern
[http://www.linuxpedia.org/index.php?title=Linux POSIX Message Queue]
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 53 / 58
Producer-Consumer via Message Queue (1/2)
Producer
char *my_mq = "/mymq";
char *write_msg = "hello";
mqd_t mqd;
// Open an existing message queue
mqd = mq_open(my_mq, O_WRONLY);
// Write "hello" to the message queue
mq_send(mqd, write_msg, strlen(write_msg), 0);
// Close the message queue
mq_close(mqd);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 54 / 58
Producer-Consumer via Message Queue (2/2)
Consumer
#define MQ_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
int MAX_SIZE = 100;
int MAX_NUM_MSG = 10;
char *my_mq = "/mymq";
char buf[MAX_SIZE];
mqd_t mqd;
struct mq_attr attr;
// Form the queue attributes
attr.mq_maxmsg = MAX_NUM_MSG;
attr.mq_msgsize = MAX_SIZE;
// Create message queue
mqd = mq_open(my_mq, O_RDONLY | O_CREAT, MQ_MODE, &attr);
// Read the message from the message queue
mq_receive(mqd, buf, MAX_NUM_MSG, NULL);
printf("Message: %sn", buf);
// Close the message queue
mq_close(mqd);
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 55 / 58
Summary
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 56 / 58
Summary
Inter-Process Communication: shared memory vs. message passing
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
Summary
Inter-Process Communication: shared memory vs. message passing
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
Summary
Inter-Process Communication: shared memory vs. message passing
Message passing: data messages vs. stream
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
Summary
Inter-Process Communication: shared memory vs. message passing
Message passing: data messages vs. stream
Data stream: pipe, FIFO
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
Summary
Inter-Process Communication: shared memory vs. message passing
Message passing: data messages vs. stream
Data stream: pipe, FIFO
Data message: message queue
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
Questions?
Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 58 / 58

More Related Content

What's hot

CPU Scheduling - Part2
CPU Scheduling - Part2CPU Scheduling - Part2
CPU Scheduling - Part2Amir Payberah
 
Realization of high performance run time loadable mips soft-core processor
Realization of high performance run time loadable mips soft-core processorRealization of high performance run time loadable mips soft-core processor
Realization of high performance run time loadable mips soft-core processoreSAT Publishing House
 
pipeline and vector processing
pipeline and vector processingpipeline and vector processing
pipeline and vector processingAcad
 
Pipelining in Computer System Achitecture
Pipelining in Computer System AchitecturePipelining in Computer System Achitecture
Pipelining in Computer System AchitectureYashiUpadhyay3
 
Design an I/O system
Design an I/O systemDesign an I/O system
Design an I/O systemAARTHI SEETHA
 
Computer organization
Computer organization Computer organization
Computer organization vishnu973656
 
Interrupt handling
Interrupt handlingInterrupt handling
Interrupt handlingmaverick2203
 
Dealing with exceptions Computer Architecture part 2
Dealing with exceptions Computer Architecture part 2Dealing with exceptions Computer Architecture part 2
Dealing with exceptions Computer Architecture part 2Gaditek
 
Advanced computer architecture
Advanced computer architectureAdvanced computer architecture
Advanced computer architecturevamsi krishna
 

What's hot (20)

Protection
ProtectionProtection
Protection
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
CPU Scheduling - Part2
CPU Scheduling - Part2CPU Scheduling - Part2
CPU Scheduling - Part2
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Security
SecuritySecurity
Security
 
Realization of high performance run time loadable mips soft-core processor
Realization of high performance run time loadable mips soft-core processorRealization of high performance run time loadable mips soft-core processor
Realization of high performance run time loadable mips soft-core processor
 
pipeline and vector processing
pipeline and vector processingpipeline and vector processing
pipeline and vector processing
 
Presentation on risc pipeline
Presentation on risc pipelinePresentation on risc pipeline
Presentation on risc pipeline
 
Lecture 27
Lecture 27Lecture 27
Lecture 27
 
IO Management
IO ManagementIO Management
IO Management
 
Pipelining in Computer System Achitecture
Pipelining in Computer System AchitecturePipelining in Computer System Achitecture
Pipelining in Computer System Achitecture
 
I/O Management
I/O ManagementI/O Management
I/O Management
 
Lecture 28
Lecture 28Lecture 28
Lecture 28
 
Design an I/O system
Design an I/O systemDesign an I/O system
Design an I/O system
 
Unit 3
Unit 3Unit 3
Unit 3
 
Lecture 46
Lecture 46Lecture 46
Lecture 46
 
Computer organization
Computer organization Computer organization
Computer organization
 
Interrupt handling
Interrupt handlingInterrupt handling
Interrupt handling
 
Dealing with exceptions Computer Architecture part 2
Dealing with exceptions Computer Architecture part 2Dealing with exceptions Computer Architecture part 2
Dealing with exceptions Computer Architecture part 2
 
Advanced computer architecture
Advanced computer architectureAdvanced computer architecture
Advanced computer architecture
 

Viewers also liked

P2P Content Distribution Network
P2P Content Distribution NetworkP2P Content Distribution Network
P2P Content Distribution NetworkAmir Payberah
 
The Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics PlatformThe Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics PlatformAmir Payberah
 
Data Intensive Computing Frameworks
Data Intensive Computing FrameworksData Intensive Computing Frameworks
Data Intensive Computing FrameworksAmir Payberah
 
File System Interface
File System InterfaceFile System Interface
File System InterfaceAmir Payberah
 
CPU Scheduling - Part1
CPU Scheduling - Part1CPU Scheduling - Part1
CPU Scheduling - Part1Amir Payberah
 
Virtual Memory - Part1
Virtual Memory - Part1Virtual Memory - Part1
Virtual Memory - Part1Amir Payberah
 
Virtual Memory - Part2
Virtual Memory - Part2Virtual Memory - Part2
Virtual Memory - Part2Amir Payberah
 
File System Implementation - Part1
File System Implementation - Part1File System Implementation - Part1
File System Implementation - Part1Amir Payberah
 
File System Implementation - Part2
File System Implementation - Part2File System Implementation - Part2
File System Implementation - Part2Amir Payberah
 
Spark Stream and SEEP
Spark Stream and SEEPSpark Stream and SEEP
Spark Stream and SEEPAmir Payberah
 
Linux Module Programming
Linux Module ProgrammingLinux Module Programming
Linux Module ProgrammingAmir Payberah
 
MegaStore and Spanner
MegaStore and SpannerMegaStore and Spanner
MegaStore and SpannerAmir Payberah
 

Viewers also liked (17)

P2P Content Distribution Network
P2P Content Distribution NetworkP2P Content Distribution Network
P2P Content Distribution Network
 
Main Memory - Part2
Main Memory - Part2Main Memory - Part2
Main Memory - Part2
 
Storage
StorageStorage
Storage
 
The Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics PlatformThe Stratosphere Big Data Analytics Platform
The Stratosphere Big Data Analytics Platform
 
Data Intensive Computing Frameworks
Data Intensive Computing FrameworksData Intensive Computing Frameworks
Data Intensive Computing Frameworks
 
File System Interface
File System InterfaceFile System Interface
File System Interface
 
CPU Scheduling - Part1
CPU Scheduling - Part1CPU Scheduling - Part1
CPU Scheduling - Part1
 
Virtual Memory - Part1
Virtual Memory - Part1Virtual Memory - Part1
Virtual Memory - Part1
 
Virtual Memory - Part2
Virtual Memory - Part2Virtual Memory - Part2
Virtual Memory - Part2
 
File System Implementation - Part1
File System Implementation - Part1File System Implementation - Part1
File System Implementation - Part1
 
Main Memory - Part1
Main Memory - Part1Main Memory - Part1
Main Memory - Part1
 
Threads
ThreadsThreads
Threads
 
File System Implementation - Part2
File System Implementation - Part2File System Implementation - Part2
File System Implementation - Part2
 
Spark Stream and SEEP
Spark Stream and SEEPSpark Stream and SEEP
Spark Stream and SEEP
 
MapReduce
MapReduceMapReduce
MapReduce
 
Linux Module Programming
Linux Module ProgrammingLinux Module Programming
Linux Module Programming
 
MegaStore and Spanner
MegaStore and SpannerMegaStore and Spanner
MegaStore and Spanner
 

Similar to Process Management - Part2

Introduction to stream processing
Introduction to stream processingIntroduction to stream processing
Introduction to stream processingAmir Payberah
 
Farhanah binti mohd yusof
Farhanah binti mohd yusofFarhanah binti mohd yusof
Farhanah binti mohd yusofFarhanah Yusof
 
Graph processing - Pregel
Graph processing - PregelGraph processing - Pregel
Graph processing - PregelAmir Payberah
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationAnas Ebrahim
 
Advanced programming in unix.pptx
Advanced programming in unix.pptxAdvanced programming in unix.pptx
Advanced programming in unix.pptxJONASJJONAS1
 
operating system over view.ppt operating sysyems
operating system over view.ppt operating sysyemsoperating system over view.ppt operating sysyems
operating system over view.ppt operating sysyemsJyoReddy9
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3Dwight Sabio
 
PROCESS Management presentation processins.pdf
PROCESS Management presentation processins.pdfPROCESS Management presentation processins.pdf
PROCESS Management presentation processins.pdfPDhivyabharathi2
 
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.pptModule-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.pptKAnurag2
 
System Calls - Introduction
System Calls - IntroductionSystem Calls - Introduction
System Calls - IntroductionTo Sum It Up
 

Similar to Process Management - Part2 (20)

Chubby
ChubbyChubby
Chubby
 
Introduction to stream processing
Introduction to stream processingIntroduction to stream processing
Introduction to stream processing
 
Farhanah binti mohd yusof
Farhanah binti mohd yusofFarhanah binti mohd yusof
Farhanah binti mohd yusof
 
Paxos
PaxosPaxos
Paxos
 
Graph processing - Pregel
Graph processing - PregelGraph processing - Pregel
Graph processing - Pregel
 
Bigtable
BigtableBigtable
Bigtable
 
Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
 
Advanced programming in unix.pptx
Advanced programming in unix.pptxAdvanced programming in unix.pptx
Advanced programming in unix.pptx
 
Operating system
Operating systemOperating system
Operating system
 
Chapter 3 - Processes
Chapter 3 - ProcessesChapter 3 - Processes
Chapter 3 - Processes
 
Ch03
Ch03Ch03
Ch03
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
 
operating system over view.ppt operating sysyems
operating system over view.ppt operating sysyemsoperating system over view.ppt operating sysyems
operating system over view.ppt operating sysyems
 
Ch3OperSys
Ch3OperSysCh3OperSys
Ch3OperSys
 
OperatingSystemChp3
OperatingSystemChp3OperatingSystemChp3
OperatingSystemChp3
 
PROCESS Management presentation processins.pdf
PROCESS Management presentation processins.pdfPROCESS Management presentation processins.pdf
PROCESS Management presentation processins.pdf
 
Ch03- PROCESSES.ppt
Ch03- PROCESSES.pptCh03- PROCESSES.ppt
Ch03- PROCESSES.ppt
 
ch3_smu.ppt
ch3_smu.pptch3_smu.ppt
ch3_smu.ppt
 
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.pptModule-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
Module-6 process managedf;jsovj;ksdv;sdkvnksdnvldknvlkdfsment.ppt
 
System Calls - Introduction
System Calls - IntroductionSystem Calls - Introduction
System Calls - Introduction
 

Recently uploaded

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 

Recently uploaded (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 

Process Management - Part2

  • 1. Processes (Part II) Amir H. Payberah amir@sics.se Amirkabir University of Technology (Tehran Polytechnic) Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 1 / 58
  • 2. Inter-Process Communication (IPC) Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 2 / 58
  • 3. Cooperating Processes Processes within a system may be independent or cooperating. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
  • 4. Cooperating Processes Processes within a system may be independent or cooperating. • Independent process cannot affect or be affected by the execution of another process. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
  • 5. Cooperating Processes Processes within a system may be independent or cooperating. • Independent process cannot affect or be affected by the execution of another process. • Cooperating process can affect or be affected by other processes. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
  • 6. Cooperating Processes Processes within a system may be independent or cooperating. • Independent process cannot affect or be affected by the execution of another process. • Cooperating process can affect or be affected by other processes. Reasons for cooperating processes: information sharing, computa- tion speedup, ... Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
  • 7. Cooperating Processes Processes within a system may be independent or cooperating. • Independent process cannot affect or be affected by the execution of another process. • Cooperating process can affect or be affected by other processes. Reasons for cooperating processes: information sharing, computa- tion speedup, ... Producer-Consumer model: producer process produces information that is consumed by a consumer process. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 3 / 58
  • 8. Inter-Process Communication Cooperating processes require an interprocess communication (IPC) mechanism that will allow them to exchange data and information. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 4 / 58
  • 9. Inter-Process Communication Cooperating processes require an interprocess communication (IPC) mechanism that will allow them to exchange data and information. Two models of IPC • Shared memory • Message passing Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 4 / 58
  • 10. Shared Memory Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 5 / 58
  • 11. Shared Memory (1/3) An area of memory shared among the processes that wish to com- municate. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 6 / 58
  • 12. Shared Memory (2/3) It is resides in the address space of the process creating the shared- memory segment. Other processes must attach it to their address space for communi- cation. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 7 / 58
  • 13. Shared Memory (3/3) But, OS prevents one process from accessing another process’s memory. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 8 / 58
  • 14. Shared Memory (3/3) But, OS prevents one process from accessing another process’s memory. Shared memory requires that two or more processes agree to remove this restriction. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 8 / 58
  • 15. Shared Memory (3/3) But, OS prevents one process from accessing another process’s memory. Shared memory requires that two or more processes agree to remove this restriction. The communication is under the control of the users processes not the OS. • Synchronization Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 8 / 58
  • 16. Shared Memory - Producer-Consumer Model (1/3) Defining the buffer. • Unbounded buffer: no practical limit on the size of the buffer. • Bounded buffer: a fixed buffer size. #define BUFFER_SIZE 10 typedef struct { ... } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 9 / 58
  • 17. Shared Memory - Producer-Consumer Model (2/3) Producer item next_produced; while (true) { // produce an item in next produced while (((in + 1) % BUFFER_SIZE) == out) { // do nothing } buffer[in] = next_produced; in = (in + 1) % BUFFER_SIZE; } Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 10 / 58
  • 18. Shared Memory - Producer-Consumer Model (3/3) Consumer item next_consumed; while (true) { while (in == out) { // do nothing } next_consumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; // consume the item in next consumed } Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 11 / 58
  • 19. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 12 / 58
  • 20. A Taxonomy of Linux IPC Facilities [Michael Kerrisk, The Linux Programming Interface, No Starch Press, 2010] Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 13 / 58
  • 21. System V vs. POSIX IPC System V (System Five): one of the first commercial versions of the Unix OS. POSIX (Portable Operating System Interface): a family of standards for maintaining compatibility between OSs. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 14 / 58
  • 22. System V vs. POSIX IPC System V (System Five): one of the first commercial versions of the Unix OS. POSIX (Portable Operating System Interface): a family of standards for maintaining compatibility between OSs. Both have the same basic IPC tools, but they offer a slightly different interfaces to those tools. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 14 / 58
  • 23. System V vs. POSIX IPC System V (System Five): one of the first commercial versions of the Unix OS. POSIX (Portable Operating System Interface): a family of standards for maintaining compatibility between OSs. Both have the same basic IPC tools, but they offer a slightly different interfaces to those tools. System V is fully supported on all Linux kernels. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 14 / 58
  • 24. POSIX Shared Memory To use a POSIX shared memory object, we perform two steps: 1 Use the shm open() function to open an object with a specified name. 2 Pass the file descriptor obtained in the previous step in a call to mmap() that maps the shared memory object into the process’s virtual address space. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 15 / 58
  • 25. Creating Shared Memory Objects shm open() creates and opens a new shared memory object or opens an existing object. mmap() creates a new mapping in the virtual address space of the calling process. #include <fcntl.h> #include <sys/stat.h> #include <sys/mman.h> int shm_open(const char *name, int oflag, mode_t mode); void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 16 / 58
  • 26. Removing Shared Memory Objects shm unlink() removes a shared memory object. #include <sys/mman.h> int shm_unlink(const char *name); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 17 / 58
  • 27. Producer-Consumer via Shared Memory (1/2) Producer int SIZE = 4096; char *my_shm = "/tmp/myshm"; char *write_msg = "hello"; char *addr; int fd; // create the shared memory object fd = shm_open(my_shm, O_CREATE | O_RDWR, 0666); // configuare the size of the shared memory object ftruncate(fd, SIZE); // memory map to the shared memory object addr = mmap(NULL, SIZE, PROT_WRITE, MAP_SHARED, fd, 0); // write to the shared object sprintf(addr, "%s", write_msg); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 18 / 58
  • 28. Producer-Consumer via Shared Memory (2/2) Consumer int SIZE = 4096; char *my_shm = "/tmp/myshm"; char *addr; int fd; // open the shared memory object fd = shm_open(my_shm, O_RDONLY, 0666); // memory map to the shared memory object addr = mmap(NULL, SIZE, PROT_READ, MAP_SHARED, fd, 0); // read from to the shared object printf("%s", (char *)addr); // remove the shared memory object shm_unlink("my_shm"); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 19 / 58
  • 29. Message Passing Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 20 / 58
  • 30. Message Passing (1/2) Processes communicate with each other without resorting to shared variables. Useful in a distributed environment: processes on different comput- ers. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 21 / 58
  • 31. Message Passing (2/2) Two operations: send(message) and receive(message). If processes p and q wish to communicate, they need to: • Establish a communication link between them. • Exchange messages via send and receive. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 22 / 58
  • 32. Message Passing (2/2) Two operations: send(message) and receive(message). If processes p and q wish to communicate, they need to: • Establish a communication link between them. • Exchange messages via send and receive. Implementation of communication link: • Physical links, e.g., shared memory, hardware bus, network • Logical links Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 22 / 58
  • 33. Logical Links Naming: direct or indirect communication Synchronization: synchronous or asynchronous communication Buffering: automatic or explicit buffering Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 23 / 58
  • 34. Naming (1/3) With direct communication, processes must name each other ex- plicitly: • send(p, message): sends a message to process p. • receive(q, message): receives a message from process q. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 24 / 58
  • 35. Naming (1/3) With direct communication, processes must name each other ex- plicitly: • send(p, message): sends a message to process p. • receive(q, message): receives a message from process q. Properties of communication link: • A link is associated with exactly two processes. • Between each pair of processes, there exists exactly one link. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 24 / 58
  • 36. Naming (2/3) With indirect communication the messages are sent to and received from mailboxes or ports. • send(A, message): sends a message to mailbox A. • receive(A, message): receives a message from mailbox A. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 25 / 58
  • 37. Naming (2/3) With indirect communication the messages are sent to and received from mailboxes or ports. • send(A, message): sends a message to mailbox A. • receive(A, message): receives a message from mailbox A. Properties of communication link: • A link is established only if processes share a common mailbox. • A link may be associated with more than two processes. • Each pair of processes may share several communication links. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 25 / 58
  • 38. Naming (3/3) Mailbox sharing • p1, p2, and p3 share mailbox A. • p1 sends; p2 and p3 receive. • Who gets the message? Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 26 / 58
  • 39. Naming (3/3) Mailbox sharing • p1, p2, and p3 share mailbox A. • p1 sends; p2 and p3 receive. • Who gets the message? Solutions • Allow a link to be associated with at most two processes. • Allow only one process at a time to execute a receive operation. • Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 26 / 58
  • 40. Synchronization (1/2) Message passing may be either blocking or non-blocking. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 27 / 58
  • 41. Synchronization (1/2) Message passing may be either blocking or non-blocking. Blocking is considered synchronous. • Blocking send: the sender is blocked until the message is received. • Blocking receive: the receiver is blocked until a message is available. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 27 / 58
  • 42. Synchronization (1/2) Message passing may be either blocking or non-blocking. Blocking is considered synchronous. • Blocking send: the sender is blocked until the message is received. • Blocking receive: the receiver is blocked until a message is available. Non-blocking is considered asynchronous. • Non-blocking send: the sender sends the message and continue. • Non-blocking receive: the receiver receives a valid message, or null message. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 27 / 58
  • 43. Synchronization (2/2) Producer-consumer model // producer // message: next_produced; while (true) { // produce an item in next produced send(next_produced); } // consumer // message: next_consumed; while (true) { receive(next_consumed); // consume the item in next consumed } Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 28 / 58
  • 44. Buffering Queue of the messages attached to the link. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 29 / 58
  • 45. Buffering Queue of the messages attached to the link. Implemented in one of three ways: • Zero capacity: no messages are queued on a link. Sender must wait for receiver. • Bounded capacity: finite length of n messages Sender must wait if link full. • Unbounded capacity: infinite length. Sender never waits. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 29 / 58
  • 46. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 30 / 58
  • 47. A Taxonomy of Linux IPC Facilities [Michael Kerrisk, The Linux Programming Interface, No Starch Press, 2010] Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 31 / 58
  • 48. Data Message vs. Data Stream (1/2) Message oriented protocols send data in distinct chunks or groups. • The receiver of data can determine where one message ends and another begins. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 32 / 58
  • 49. Data Message vs. Data Stream (1/2) Message oriented protocols send data in distinct chunks or groups. • The receiver of data can determine where one message ends and another begins. Stream protocols send a continuous flow of data. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 32 / 58
  • 50. Data Message vs. Data Stream (2/2) Example with mobile phones: text messages would be a message oriented protocol, and a phone call is stream oriented. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 33 / 58
  • 51. Data Message vs. Data Stream (2/2) Example with mobile phones: text messages would be a message oriented protocol, and a phone call is stream oriented. UDP is a message oriented protocol, and TCP is a stream oriented protocol. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 33 / 58
  • 52. Message Passing IPC Facilities Data stream: • Pipe • FIFO (named pipe) • Stream socket Data message: • Message queue • Datagram socket Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 34 / 58
  • 53. Pipe Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 35 / 58
  • 54. Pipe Pipes allow two processes to communicate in standard producer- consumer fashion. • The producer writes to the write-end, and the consumer reads from the read-end. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 36 / 58
  • 55. Pipe Pipes allow two processes to communicate in standard producer- consumer fashion. • The producer writes to the write-end, and the consumer reads from the read-end. Pipes are unidirectional, allowing only one-way communication. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 36 / 58
  • 56. Pipe Pipes allow two processes to communicate in standard producer- consumer fashion. • The producer writes to the write-end, and the consumer reads from the read-end. Pipes are unidirectional, allowing only one-way communication. Require parent-child relationship between communicating processes. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 36 / 58
  • 57. Pipe Pipes allow two processes to communicate in standard producer- consumer fashion. • The producer writes to the write-end, and the consumer reads from the read-end. Pipes are unidirectional, allowing only one-way communication. Require parent-child relationship between communicating processes. ls | wc -l Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 36 / 58
  • 58. Creating a Pipe The pipe() system call creates a new pipe. It returns two open file descriptors in the array fd: fd[0] to read from the pipe, and fd[1] to write to the pipe. #include <unistd.h> int pipe(int fd[2]); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 37 / 58
  • 59. Parent-Child Communication Through a Pipe (1/2) int BUFFER_SIZE = 25; char write_msg[BUFFER_SIZE] = "hello"; char read_msg[BUFFER_SIZE]; int fd[2]; pipe(fd); // Create the pipe switch (fork()) { case -1: // fork error break; case 0: // Child close(fd[1]); // Close unused write end read(fd[0], read_msg, BUFFER_SIZE); printf("read %s", read_msg); break; default: // Parent close(fd[0]) // Close unused read end write(fd[1], write_msg, strlen(write_msg) + 1); break; } Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 38 / 58
  • 60. Parent-Child Communication Through a Pipe (2/2) [Michael Kerrisk, The Linux Programming Interface, No Starch Press, 2010] Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 39 / 58
  • 61. FIFO Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 40 / 58
  • 62. FIFO (Named Pipe) FIFO is similar to a pipe, but it has a name within the file system and is opened in the same way as a regular file. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 41 / 58
  • 63. FIFO (Named Pipe) FIFO is similar to a pipe, but it has a name within the file system and is opened in the same way as a regular file. Communication is bidirectional. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 41 / 58
  • 64. FIFO (Named Pipe) FIFO is similar to a pipe, but it has a name within the file system and is opened in the same way as a regular file. Communication is bidirectional. No parent-child relationship is necessary. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 41 / 58
  • 65. FIFO (Named Pipe) FIFO is similar to a pipe, but it has a name within the file system and is opened in the same way as a regular file. Communication is bidirectional. No parent-child relationship is necessary. Several processes can use a FIFO for communication. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 41 / 58
  • 66. Creating a FIFO The mkfifo() function creates a new FIFO. #include <sys/stat.h> int mkfifo(const char *pathname, mode_t mode); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 42 / 58
  • 67. Producer-Consumer via FIFO (1/2) Producer char *my_fifo = "/tmp/myfifo"; char *write_msg = "hello"; int fd; // Create the FIFO (named pipe) mkfifo(my_fifo, 0666); // Write "hello" to the FIFO fd = open(my_fifo, O_WRONLY); write(fd, write_msg, strlen(write_msg)); close(fd); // Remove the FIFO unlink(my_fifo); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 43 / 58
  • 68. Producer-Consumer via FIFO (2/2) Consumer int MAX_SIZE = 100; char *my_fifo = "/tmp/myfifo"; char buf[MAX_SIZE]; int fd; // Open the FIFO fd = open(my_fifo, O_RDONLY); // Read the message from the FIFO read(fd, buf, MAX_SIZE); printf("Received: %sn", buf); // Close the FIFO close(fd); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 44 / 58
  • 69. Message Queue Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 45 / 58
  • 70. Message Queue Message queues allows processes to exchange data in the form of messages. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 46 / 58
  • 71. Message Queue Message queues allows processes to exchange data in the form of messages. In message queue the consumer receives whole messages, as written by the producer. • It is not possible to read part of a message and leave the remainder in the queue, or to read multiple messages at a time. • In pipes, the consumer can read an arbitrary number of bytes at a time, irrespective of the size of data blocks written by the producer. Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 46 / 58
  • 72. Creating a Message Queue mq open() creates a new message queue or opens an existing queue. #include <fcntl.h> #include <sys/stat.h> #include <mqueue.h> mqd_t mq_open(const char *name, int oflag, ... /* mode_t mode, struct mq_attr *attr */ ); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 47 / 58
  • 73. Closing a Message Queue mq close() closes the message queue descriptor mqdes. #include <mqueue.h> int mq_close(mqd_t mqdes); mq unlink() removes the message queue identified by name. #include <mqueue.h> int mq_unlink(const char *name); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 48 / 58
  • 74. Message Queue Attributes Specifies attributes of a message queue. struct mq_attr { long mq_flags; // Message queue description flags long mq_maxmsg; // Maximum number of messages on queue long mq_msgsize; // Maximum message size (in bytes) long mq_curmsgs; // Number of messages currently in queue }; Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 49 / 58
  • 75. Retrieving and Modifying a Message Queue Attributes mq getattr() returns a mq attr structure of the message queue. #include <mqueue.h> int mq_getattr(mqd_t mqdes, struct mq_attr *attr); mq setattr() sets attributes of the message queue. #include <mqueue.h> int mq_setattr(mqd_t mqdes, const struct mq_attr *newattr, struct mq_attr *oldattr); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 50 / 58
  • 76. Sending and Receiving Messages mq send() adds the message msg ptr to the message queue. #include <mqueue.h> int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio); mq receive() removes the oldest message from the message queue. #include <mqueue.h> ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 51 / 58
  • 77. Message Notification A way for asynchronous communications. A process can request a notification of message arrival and then performs other tasks until it is notified. The mq notify() registers the calling process to receive a notifica- tion when a message arrives on the empty queue. #include <mqueue.h> int mq_notify(mqd_t mqdes, const struct sigevent *notification); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 52 / 58
  • 78. Linux Message Queue Pattern [http://www.linuxpedia.org/index.php?title=Linux POSIX Message Queue] Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 53 / 58
  • 79. Producer-Consumer via Message Queue (1/2) Producer char *my_mq = "/mymq"; char *write_msg = "hello"; mqd_t mqd; // Open an existing message queue mqd = mq_open(my_mq, O_WRONLY); // Write "hello" to the message queue mq_send(mqd, write_msg, strlen(write_msg), 0); // Close the message queue mq_close(mqd); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 54 / 58
  • 80. Producer-Consumer via Message Queue (2/2) Consumer #define MQ_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) int MAX_SIZE = 100; int MAX_NUM_MSG = 10; char *my_mq = "/mymq"; char buf[MAX_SIZE]; mqd_t mqd; struct mq_attr attr; // Form the queue attributes attr.mq_maxmsg = MAX_NUM_MSG; attr.mq_msgsize = MAX_SIZE; // Create message queue mqd = mq_open(my_mq, O_RDONLY | O_CREAT, MQ_MODE, &attr); // Read the message from the message queue mq_receive(mqd, buf, MAX_NUM_MSG, NULL); printf("Message: %sn", buf); // Close the message queue mq_close(mqd); Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 55 / 58
  • 81. Summary Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 56 / 58
  • 82. Summary Inter-Process Communication: shared memory vs. message passing Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
  • 83. Summary Inter-Process Communication: shared memory vs. message passing Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
  • 84. Summary Inter-Process Communication: shared memory vs. message passing Message passing: data messages vs. stream Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
  • 85. Summary Inter-Process Communication: shared memory vs. message passing Message passing: data messages vs. stream Data stream: pipe, FIFO Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
  • 86. Summary Inter-Process Communication: shared memory vs. message passing Message passing: data messages vs. stream Data stream: pipe, FIFO Data message: message queue Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 57 / 58
  • 87. Questions? Amir H. Payberah (Tehran Polytechnic) Processes 1393/7/5 58 / 58