Background information:
Process
- A
computer program
is a passive
collection of instructions
stored in a
file on disk
-
Process =
a
running program
=
a computer program that is
being executed
- A computer system can
have multiple processes:
-
Goal of
studying a
process
- Understand
how to
pause
a running program (= process)
|
|
Background information:
Process
Difference between
a process and
a program:
(from Wikipedia)
Program = static
and makes no progress
Process = dynamic
(being run on a
CPU) and
has a
process state
Background information:
Current Process
Background information:
progress in program execution
- The are many
processes in a
computer system
- For a
single core
CPU computer, there is
exactly
one
current process
- Let's assume the
computer hss a
single core
CPU for
simplicity
|
(In multi-processor systems, the
number of current processes is
equal to the
number of CPUs)
- Only the
current process makes
progress in
its program execution
(because the CPU
only executes
instructions
fetched from the
current process)
- All
other processes
are
paused !!!
|
- Important fact from
CS255:
- The
current process
is using
CPU registers
in its execution !!
|
This fact is
important for
how to
pause
the current process !
|
Background information:
switching current process
The process (program) P2
is currently
running
(= making progress)
Background information:
switching current process
The process P2 has
temporally
stopped running !!
Background information:
switching current process
The process (program) P2
will
resume from the
paused
program location !!!
How to switch
the current process ?
What does it
take to
switch
the current process:
- We must
stop the
current process
(= the currently running program)
"carefully":
- We must
stop it
in
such a way that
the
stopped process can
be
restarted (= resumed)
at a later time !!!
|
How to
stop the
current process:
- We must
save
the necessary information
in order for the
current process
to resume
- The
data structure used to
save the
process' information
is called the
Process Control Block (PCB)
|
- After stopping
the current process, we
must
restart a
(previously stopped) process
(this process will
become the
new current process)
|
How can we
stop a
running program so that it can be
restarted at a later time ???
Suppose the
process P1 is
current running (current process):
Question:
what data does the
computer system
need to have
to restart
a running program ??
How can we
stop a
running program so that it can be
restarted at a later time ???
Obvious answer:
the
computer instructions of
process P1
Assumption:
we keep
all instructions of
the process in
RAM.
Anything else
we need ?
(
Note: the
OS can
save the
running program on
disk to
free up some
memory if
needed)
How can we
stop a
running program so that it can be
restarted at a later time ???
Another data needed:
the
location of the
current computer instruction
(where to
resume)
Solution:
we
save
the PC
in a
Process Control Block
data structure
Anything else
we need ?
Note:
we will see later that we
actually need to
save the
LR register
(it calls the
OS to
perform IO)
How can we
stop a
running program so that it can be
restarted at a later time ???
Finally:
the
values
in the
general purpose registers
and the
PSR
(temporal results !)
Solution:
we also
save
all these registers
in the
Process Control Block data structure
Process context (= context information)
and context switching
The effect of
a context switching operation
The effect achieved
by a context switching operation is
very remarkable:
- Saving the
context information of the
current process into
its PCB (Process Control Block)
- This step in the
context switching operation will
pause the
current process in a
manner that it can
resume at a
later time
from the
paused location
|
- Load the
context information stored inside
another
PCB (Process Control Block)
into the general purpose registers, PSR
and PC
- This step in the
context switching operation will
resume
a
previously
paused process
so it becomes the
new
current (running) process
|
|
The effect
of a context switching operation -
graphically explained
Before a
context switching operation:
After a
context switching operation:
DEMO:
demo/Co-process/main.c
Analogy of context switching
❮
❯