Professional Documents
Culture Documents
OUTLINE
Process Concept
Process Scheduling
Operations on Processes
Inter-process Communication
Examples of IPC Systems
Communication in Client-Server Systems
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Fork( ) ?
Process creation
Parent process create children process, which, in turn create other processes, forming a
tree of processes
Child process contains exact copy of the memory space of the parent process.
Child process contains the same text/code section but executes independently
Exec()
Exec is a collection of function e.g., execlp(), ececve(), execl(), are use to execute any
program/script.
Typically exec used after a fork() by child process to replace the memory space with a
new program.
PID does not change but the data, heap, and stack of the child are replace by new
program
Process creation (cont..)
Exec( ) system call used after fork to replace the process memory space with a new
program.
Process Termination
Process executes last statement and asks the operating system to delete it (exit)
Process resources are deallocated by operating system
PC PC
x pid y pid
PCB-Parent PCB-Child
sys_fork()
Kernel {….}
RAM
16
PC PC
x pid y pid
PCB-Parent PCB-Child
sys_fork() sys_execve()
Kernel {….} {….}
RAM
Process Queues and
Scheduling
18
Process Scheduling
The scheduling mechanism (dispatcher) than assigns the selected process to the CPU and
starts execution of it.
Select Dispatch
(Scheduling Algorithm) (mechanism)
19
Scheduling
Ready queue is one of the many queues that a process may be Process/CPU scheduling
added
Device
CPU scheduling schedules from ready queue. queue
CPU Device
Other queues possible:
Job queue – set of all processes started in the system waiting
Ready Device
for memory
queue queue
one process from there Device
Device queues – set of processes waiting for an I/O device
Memory
A process will wait in such a queue until I/O is finished
or until the waited event happens
ready queue
I/O queue
Scheduler
Long-term scheduler (or job scheduler) -- selects which processes should be brought into
ready queue
Short term scheduler (or CPU scheduler) -- selects which process should be executed next
and allocates CPU
23
Context Switch
When CPU switches to another process, the system must save the state of the old process
and load the saved state for the new process via a context switch
Context-switch time is overhead; the system does no useful work while switching
Shared memory
Massage passing
IPC communication models
message passing approach shared memory approach
IPC Examples …
Sockets
Pipes
Socket Communication
30
Sockets
P Q
Network
M1 M2
Shared Memory IPC Mechanism 31
Kernel
32
Shared data
#define BUFFER_SIZE 10
typedef struct {
...
} item;
item buffer[BUFFER_SIZE];
int in = 0; // next free position
int out = 0; // first full position
item buffer[BUFFER_SIZE]
Producer Consumer
int out;
int in;
Shared Memory
35
Buffer State in Shared Memory
Buffer Full
in out
((in+1) % BUFFER_SIZE == out) : considered full buffer
Buffer Empty
in out
Client Client
fifo Server fifo
fifo
Client-request Client-request
Client 1 Client 2
41
Process Process
Indirect naming and communication
Messages are directed and received from mailboxes (also referred to as ports)
send() receive()
send (mqid, message) Mailbox (mqid)
{.. {…
receive (mqid, message) { }
Kernel
43
Synchronization
How does the sender/receiver behave if it can not send/receive the message immediately
Depend if Blocking or Non-Blocking communication is used
Buffering