CH 3
CH 3
CH 3
Outline
▪ Process Concept
▪ Process Scheduling
▪ Operations on Processes
▪ Interprocess Communication
▪ IPC in Shared-Memory Systems
▪ IPC in Message-Passing Systems
▪ Examples of IPC Systems
▪ Communication in Client-Server Systems
Objectives
▪ Identify the separate components of a process and illustrate
how they are represented and scheduled in an operating
system.
▪ Describe how processes are created and terminated in an
operating system, including developing programs using the
appropriate system calls that perform these operations.
▪ Describe and contrast interprocess communication using
shared memory and message passing.
▪ Design programs that uses pipes and POSIX shared
memory to perform interprocess communication.
▪ Describe client-server communication using sockets and
remote procedure calls.
▪ Design kernel modules that interact with the Linux operating
system.
Process Concept
▪ An operating system executes a variety of programs that run
as a process.
▪ Process – a program in execution; process execution must
progress in sequential fashion. No parallel execution of
instructions of a single process
▪ Multiple parts
• The program code, also called text section
• Current activity including program counter, processor
registers
• Stack containing temporary data
Function parameters, return addresses, local variables
• Data section containing global variables
• Heap containing memory dynamically allocated during
run time
Process Concept (Cont.)
▪ Shared data
#define BUFFER_SIZE 10
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
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;
}
Consumer Process – Shared Memory
item next_consumed;
while (true) {
while (in == out)
; /* do nothing */
next_consumed = buffer[out];
out = (out + 1) % BUFFER_SIZE;
while (true) {
/* produce an item in next produced */
▪ Physical:
• Shared memory
• Hardware bus
• Network
▪ Logical:
• Direct or indirect
• Synchronous or asynchronous
• Automatic or explicit buffering
Direct Communication
▪ Operations
• Create a new mailbox (port)
• Send and receive messages through mailbox
• Delete a mailbox
▪ Primitives are defined as:
• send(A, message) – send a message to mailbox A
• receive(A, message) – receive a message from
mailbox A
Indirect Communication (Cont.)
▪ 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.
Synchronization
send(next_produced);
}
▪ Consumer
message next_consumed;
while (true) {
receive(next_consumed)
#include<mach/mach.h>
struct message {
mach_msg_header_t header;
int data;
};
▪ Sockets
▪ Remote Procedure Calls
Sockets