OS 4 Processes
OS 4 Processes
PROCESSES
OUTLINE
• Process Concept
• Process Scheduling
• Operations on Processes
• Interprocess Communication
– IPC in Shared-Memory Systems
– IPC in Message-Passing Systems
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.)
• Program is passive entity stored on disk
(executable file); process is active
– Program becomes process when an
executable file is loaded into memory
• Execution of program started via GUI
mouse clicks, command line entry of its
name, etc.
• One program can be several processes
– Consider multiple users executing the same
program
Process in Memory
Memory Layout of a C Program
Process States
• As a process executes, it changes state
• Shared data
#define BUFFER_SIZE 10
typedef struct {
. . .
} item;
item buffer[BUFFER_SIZE];
int in = 0;
int out = 0;
Producer Process – Shared Memory
item next_produced;
while(true) {
/* produce an item in next_produced */
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;
• 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
• Producer
message next_produced;
while (true) {
/* produce an item in next_produced */
send(next_produced);
}
• Consumer
message next_consumed;
while (true) {
receive(next_consumed)