Princess Nora University
Computer Sciences Department
Operating Systems
CS 340
1
Chapter-2
Process Concept
(covered in chapter 3 of textbook)
Introduction
Chapter 2: Process-Concept
1. Process Concept
2. Process Scheduling
3. Inter-process Communication
3
OBJECTIVES:
▪ To introduce the notion of a process
▪ To describe the various features of processes, including
scheduling, creation and termination, and communication
▪ To explore interprocess communication using shared
memory and message passing
4
PROCESS CONCEPT
5
Process Concept
System consists of a collection of processes:
▪
❑ Operating system processes executing system code
❑ User processes executing user code
The terms job and process are used almost
interchangeably, and both refer to the same meaning:
▪
=
( a program that is loaded into memory
and in execution)
6
Process Concept (cont..)
➢
➢
Program : is a collection of instruction in a code
manner , which is sometimes known as the text section.
▪
Program = passive entity
▪
Process =Active entity
Process :is more general than program as it includes more
details such as :
o Text section
o Stack section
o Data section
o The current activity section
o Heap section
7
The Process (cont..)
contains temporary data (such as function
parameters, return addresses, and local
variables
The current activity: the value of the
program counter & contents of the processor’s
registers.
is memory that is dynamically allocated
during process run time.
which contains global variables.
which is program code .
8
Process State
Process state is defined by the current activity of that
process.
➢ As a process executes, it changes state
▪ New: the process is being created
▪ Running: instructions are being executed
▪ Waiting: the process is waiting for some event to occur
(e.g. An I/O completion).
▪ Ready: the process is waiting to be assigned to a
processor
▪ Terminated: the process has finished execution
➢ Only one process can be running on any processor at any
instant. Many processes may be ready and waiting.
➢
9
Diagram of Process State
10
Process Control Block (PCB)
➢
➢
➢
Each process is represented in the operating system by a process control
block (PCB)
PCB : is a data structure contains information about process & used by OS.
PCB contains many information including :
▪
▪
▪
▪
▪
▪
11
Process state : new/ready/ running/waiting/terminated
Program counter & CPU registers: Values of program counter & CPU registers
must be saved when an interrupt occurs to allow the process to be continued correctly
afterward
CPU scheduling information: information about when the process will be executed
in CPU.
Memory-management information: information about where the process
allocated in RAM
Accounting information :e.g . process numbers ,when the process was last run, how
much CPU time it has used
I/O status information.: the list of I/O devices allocated to the process, a list of open
files, ….etc.
Process Control Block (PCB) (cont..)
12
Time
CPU Switch From Process to Process
13
PROCESS SCHEDULING
14
Process Scheduling
🞂 Scheduler: it is an operating system module that
responsible of selecting process(/es).
Short-term
scheduler
(CPU scheduler/
process scheduler )
Schedulers
Long-term
scheduler
(job scheduler )
Medium Term
Scheduling
15
Process Scheduling Queues
➢
Job queue – set of all processes in the system residing in mass
storage.
➢
Ready queue – set of all processes residing in main memory,
ready and waiting to execute
➢ This queue is generally stored as a linked list.
➢
Device queues – set of processes waiting for an I/O device
➢ Each device has its own device queue
16
Process Scheduling Queues (cont.)
A process migrates among the various scheduling queues
throughout its lifetime:
A new process is initially put in the ready queue.
➢ It waits there until it is selected for execution.
➢ Once the process is allocated the CPU and is executing, one of
several events could occur:
➢
The process could
issue an I/O request
and then be placed
in an I/O queue.
🞂
The process could
create a new subprocess and wait
for the sub-process’s
termination
The process could be removed
forcibly from the CPU as a
result of an interrupt, and be
put back in the ready queue
A process continues this cycle until it terminates, at which
time it is removed from all queues and has its PCB and resources
deallocated.
17
Representation of Process Scheduling
18
Queuing diagram
Schedulers
➢
The operating system must select processes scheduling for these
queues.
➢
The selection process is carried out by the appropriate
scheduler.
➢
Long-term scheduler (or job scheduler) – selects which
processes should be brought from mass-storage into RAM (to the
ready queue )
➢
Short-term scheduler (or CPU scheduler) – selects which
process (from ready queue) should be executed next and
allocates CPU
19
Schedulers
🞂 Short-term scheduler is invoked very frequently (milliseconds)
⇒ (must be fast)
🞂 Long-term scheduler is invoked very infrequently (seconds,
minutes) ⇒ (may be slow)
🞂 The long-term scheduler:
Number of
processes in RAM
controls the degree of multiprogramming
20
Schedulers (Cont)
Processes can be described as either:
I/O-bound process
It spends more time doing
I/O than computations,
It has many short CPU
burst
21
CPU-bound process
It spends more time doing
computations;
It has few very long CPU
burst.
Schedulers (Cont.)
The long-term scheduler must select a good process mix of I/Obound and CPU-bound processes to improve total
performance.
If all processes are I/O bound
If all processes are CPU bound
• the ready queue will almost
• the I/O waiting queue will
always be empty,
almost always be empty,
• the short-term scheduler will • devices will go unused….
have little to do…
• (minimize devices utilization)
• (minimize CPU utilization)
▪
System with the best performance will have a combination of
CPU-bound and I/O bound processes.
22
Medium Term Scheduling
❑ Sometimes it can be advantageous to remove processes
from RAM …….(swap out)
❑ Later, the process can be reintroduced into RAM
…….(swap in), and its execution can be continued where it
left off.
❑ This scheme is called swapping. ( done by medium-term
scheduler)
❑ Swapping may be necessary to:
❑ Improve the process mix (to improve total performance)
❑ Or because a change in memory requirements has
exceeded available memory (i.e. memory is almost full)
23
Context Switch
🞂
Context Switch Time:
Is amount of time needed by OS to switch CPU from one process to
another
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 of a process represented in the PCB
🞂 Context-switch time is overhead; the system does no useful work while
switching
🞂 Time dependent on hardware support
🞂
24
Operation on Processes
OS provide mechanisms for
❖
❖
❖
25
process creation,
process termination
Process Creation
🞂 Parent process create children processes, which, in
turn create other processes, forming a tree of processes
🞂 Generally, process identified and managed via a process
identifier (pid)
🞂 Resources sharing options
Parent and children share all resources
🞂 Children share subset of parent’s resources
🞂 Parent and child share no resources
🞂
🞂 Execution options
Parent and children execute concurrently
🞂 Parent waits until children terminate
🞂
26
Process Termination
Process executes last statement and then asks the
operating system to delete it.
▪
▪
▪
Returns status value (integer)from child to parent
Process’ resources are deallocated by operating system
Parent may terminate the execution of children
processes. Some reasons for doing so:
▪
▪
▪
▪
27
Child has exceeded allocated resources
Task assigned to child is no longer required
The parent is exiting and the operating systems does not
allow a child to continue if its parent terminates
INTERPROCESS
COMMUNICATION
28
Interprocess Communication
Processes executing concurrently in the operating system may be either
independent processes or cooperating processes.
INDEPENDENT
29
COOPERATING
A process is independent
if it cannot affect or be affected
by the other processes executing
in the system.
A process is cooperating if it can
affect or be affected by other
processes executing in the
system.
✓ Does NOT share data with any
other process
✓ Shares data with other processes
Interprocess Communication
Reasons (/advantages) for cooperating processes:
1.
Information sharing : (e.g. shared file)
2.
Computation speedup:
▪ To make a particular task run faster, we must break it
into subtasks, each of which will be executing in parallel
with the others.
▪ This can be achieved only if the computer has multiple
processing elements (e.g. CPUs).
30
Interprocess Communication
Reasons (/advantages) for cooperating processes:
3. Modularity:
▪
We may want to construct the system in a modular fashion
(i.e. dividing the system functions into separate processes)
4. Convenience
▪ An individual user may work on many tasks at the same
time.
31
Interprocess Communication (Cont.)
Cooperating processes require an interprocess
communication (IPC)
▪
IPC: mechanism that will allow cooperating processes to
exchange data and information.
There are two fundamental models of IPC:
▪ shared memory
▪ message passing.
32
Interprocess Communication (Cont.)
Two models of IPC: process can exchange information by
Message passing
• Method:
messages exchanged between the
cooperating processes.
• Useful for exchanging smaller amounts of
data, because no conflicts need be
avoided.
• Easier to implement than shared memory
• Requires more system calls (interrupts)
>>> slower.
33
Shared memory
• Method:
reading and writing data to the
shared region.
• Useful for exchanging small & large
amounts of data,
• More difficult to implement than
Message passing
• Shared memory is faster than message
passing ….because only one interrupt
is generated
Communications Models
Message passing model
34
Shared memory model
Thank you
End of Chapter 2
Some Helpful Notes
🞂
Program counter :It is a register in CPU holds the address of
the next instruction to be executed for this process.
🞂 Some terminologies :
job pool= job queue= input queue
🞂 mass-storage =back-store (i.e. mostly , it is hard desk)
🞂 Shared resource: a resource allocated to multiple processes at the same time
🞂
36