COSC303_Lecture 2 Process
COSC303_Lecture 2 Process
Lecture 2: Process
1
Lecture Outline
• Process Concept
• Process Scheduling and Queues
• Operations on Processes
• Inter-process Communication
2
Process Concept and Process
Management
3
Process Concept
4
Process: program in execution
• If we have a single program running in the system, then the task of OS is easy:
– load the program, start it and program runs in CPU
– (from time to time it calls OS to get some service done)
• But if we want to start several processes, then the running program in CPU
(current process) has to be stopped for a while and other program (process)
has to run in CPU.
– Process management becomes an important issue
5
Process =! Program
6
Process State
7
Diagram of Process State
8
Process Control Block (PCB)
9
Process Scheduling and Queues
10
Process Scheduling
Select Dispatch
(Scheduling Algorithm) (mechanism)
11
Process Scheduling Queue
12
Representation of Process Scheduling
CPU Scheduler
ready queue
I/O queue
13
Schedulers
Short-term
scheduler
CPU
ready queue
job queue
14
Schedulers
15
Process Behavior
waiting waiting
16
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
17
CPU Switch from Process to Process
18
Process Creation and Termination
19
Process Creation
20
Process Creation (Cont)
• UNIX examples
– fork system call creates new process
– exec system call used after a fork to replace the process’ memory
space with a new program
21
Process Termination
22
Inter-process Communication (IPC)
23
Cooperating Processes and the need for
Interprocess Communication
• 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 the execution
of another process
Application
25
Communication Models
26
Shared Memory IPC Mechanism
27
Shared Memory IPC Mechanism
29
Implementation in a system
send() receive()
Mailbox (mqid)
{.. {…
{ }
Kernel
31
Mailbox operations, Problems, and
Solutions
• Operations
– create a new mailbox
– send/receive messages through mailbox
– destroy a mailbox
• Problems
– P1, P2 and P3 share mailbox A.
– P1 sends message, P2 and P3 receive… who gets message??
• Solutions
– disallow links between more than 2 processes
– allow only one process at a time to execute receive operation
– allow system to arbitrarily select receiver and then notify sender
32
Synchronization
33
References
34