<s>
A	O
process	B-Operating_System
is	O
a	O
program	B-Application
in	O
execution	O
,	O
and	O
an	O
integral	O
part	O
of	O
any	O
modern-day	O
operating	B-General_Concept
system	I-General_Concept
(	O
OS	B-General_Concept
)	O
.	O
</s>
<s>
The	O
OS	B-General_Concept
must	O
allocate	O
resources	O
to	O
processes	B-Operating_System
,	O
enable	O
processes	B-Operating_System
to	O
share	O
and	O
exchange	O
information	O
,	O
protect	O
the	O
resources	O
of	O
each	O
process	B-Operating_System
from	O
other	O
processes	B-Operating_System
and	O
enable	O
synchronization	O
among	O
processes	B-Operating_System
.	O
</s>
<s>
To	O
meet	O
these	O
requirements	O
,	O
the	O
OS	B-General_Concept
must	O
maintain	O
a	O
data	B-General_Concept
structure	I-General_Concept
for	O
each	O
process	B-Operating_System
,	O
which	O
describes	O
the	O
state	O
and	O
resource	O
ownership	O
of	O
that	O
process	B-Operating_System
,	O
and	O
which	O
enables	O
the	O
OS	B-General_Concept
to	O
exert	O
control	O
over	O
each	O
process	B-Operating_System
.	O
</s>
<s>
In	O
any	O
modern	O
operating	B-General_Concept
system	I-General_Concept
there	O
can	O
be	O
more	O
than	O
one	O
instance	O
of	O
a	O
program	B-Application
loaded	O
in	O
memory	O
at	O
the	O
same	O
time	O
.	O
</s>
<s>
For	O
example	O
,	O
more	O
than	O
one	O
user	O
could	O
be	O
executing	O
the	O
same	O
program	B-Application
,	O
each	O
user	O
having	O
separate	O
copies	O
of	O
the	O
program	B-Application
loaded	O
into	O
memory	O
.	O
</s>
<s>
With	O
some	O
programs	O
,	O
it	O
is	O
possible	O
to	O
have	O
one	O
copy	O
loaded	O
into	O
memory	O
,	O
while	O
several	O
users	O
have	O
shared	O
access	O
to	O
it	O
so	O
that	O
they	O
each	O
can	O
execute	O
the	O
same	O
program-code	O
.	O
</s>
<s>
Such	O
a	O
program	B-Application
is	O
said	O
to	O
be	O
re-entrant	B-Operating_System
.	O
</s>
<s>
The	O
processor	B-Architecture
at	O
any	O
instant	O
can	O
only	O
be	O
executing	O
one	O
instruction	O
from	O
one	O
program	B-Application
but	O
several	O
processes	B-Operating_System
can	O
be	O
sustained	O
over	O
a	O
period	O
of	O
time	O
by	O
assigning	O
each	O
process	B-Operating_System
to	O
the	O
processor	B-Architecture
at	O
intervals	O
while	O
the	O
remainder	O
become	O
temporarily	O
inactive	O
.	O
</s>
<s>
A	O
number	O
of	O
processes	B-Operating_System
being	O
executed	O
over	O
a	O
period	O
of	O
time	O
instead	O
of	O
at	O
the	O
same	O
time	O
is	O
called	O
concurrent	B-Architecture
execution	I-Architecture
.	O
</s>
<s>
A	O
multiprogramming	O
or	O
multitasking	B-Operating_System
OS	B-General_Concept
is	O
a	O
system	O
executing	O
many	O
processes	B-Operating_System
concurrently	O
.	O
</s>
<s>
Multiprogramming	O
requires	O
that	O
the	O
processor	B-Architecture
be	O
allocated	O
to	O
each	O
process	B-Operating_System
for	O
a	O
period	O
of	O
time	O
and	O
de-allocated	O
at	O
an	O
appropriate	O
moment	O
.	O
</s>
<s>
If	O
the	O
processor	B-Architecture
is	O
de-allocated	O
during	O
the	O
execution	O
of	O
a	O
process	B-Operating_System
,	O
it	O
must	O
be	O
done	O
in	O
such	O
a	O
way	O
that	O
it	O
can	O
be	O
restarted	O
later	O
as	O
easily	O
as	O
possible	O
.	O
</s>
<s>
There	O
are	O
two	O
possible	O
ways	O
for	O
an	O
OS	B-General_Concept
to	O
regain	O
control	O
of	O
the	O
processor	B-Architecture
during	O
a	O
program	B-Application
’s	O
execution	O
in	O
order	O
for	O
the	O
OS	B-General_Concept
to	O
perform	O
de-allocation	O
or	O
allocation	O
:	O
</s>
<s>
The	O
process	B-Operating_System
issues	O
a	O
system	B-Operating_System
call	I-Operating_System
(	O
sometimes	O
called	O
a	O
software	O
interrupt	B-Application
)	O
;	O
for	O
example	O
,	O
an	O
I/O	B-General_Concept
request	O
occurs	O
requesting	O
to	O
access	O
a	O
file	O
on	O
hard	O
disk	O
.	O
</s>
<s>
A	O
hardware	O
interrupt	B-Application
occurs	O
;	O
for	O
example	O
,	O
a	O
key	O
was	O
pressed	O
on	O
the	O
keyboard	O
,	O
or	O
a	O
timer	O
runs	O
out	O
(	O
used	O
in	O
pre-emptive	B-Operating_System
multitasking	I-Operating_System
)	O
.	O
</s>
<s>
The	O
stopping	O
of	O
one	O
process	B-Operating_System
and	O
starting	O
(	O
or	O
restarting	O
)	O
of	O
another	O
process	B-Operating_System
is	O
called	O
a	O
context	B-Operating_System
switch	I-Operating_System
or	O
context	O
change	O
.	O
</s>
<s>
In	O
many	O
modern	O
operating	B-General_Concept
systems	I-General_Concept
,	O
processes	B-Operating_System
can	O
consist	O
of	O
many	O
sub-processes	O
.	O
</s>
<s>
This	O
introduces	O
the	O
concept	O
of	O
a	O
thread	B-Operating_System
.	O
</s>
<s>
A	O
thread	B-Operating_System
may	O
be	O
viewed	O
as	O
a	O
sub-process	O
;	O
that	O
is	O
,	O
a	O
separate	O
,	O
independent	O
sequence	O
of	O
execution	O
within	O
the	O
code	O
of	O
one	O
process	B-Operating_System
.	O
</s>
<s>
Threads	B-Operating_System
are	O
becoming	O
increasingly	O
important	O
in	O
the	O
design	O
of	O
distributed	O
and	O
client	B-Operating_System
–	I-Operating_System
server	I-Operating_System
systems	O
and	O
in	O
software	O
run	O
on	O
multi-processor	B-Operating_System
systems	O
.	O
</s>
<s>
A	O
common	O
trait	O
observed	O
among	O
processes	B-Operating_System
associated	O
with	O
most	O
computer	B-Application
programs	I-Application
,	O
is	O
that	O
they	O
alternate	O
between	O
CPU	B-Device
cycles	O
and	O
I/O	B-General_Concept
cycles	O
.	O
</s>
<s>
For	O
the	O
portion	O
of	O
the	O
time	O
required	O
for	O
CPU	B-Device
cycles	O
,	O
the	O
process	B-Operating_System
is	O
being	O
executed	O
;	O
i.e.	O
</s>
<s>
is	O
occupying	O
the	O
CPU	B-Device
.	O
</s>
<s>
During	O
the	O
time	O
required	O
for	O
I/O	B-General_Concept
cycles	O
,	O
the	O
process	B-Operating_System
is	O
not	O
using	O
the	O
processor	B-Architecture
.	O
</s>
<s>
Instead	O
,	O
it	O
is	O
either	O
waiting	O
to	O
perform	O
Input/Output	B-General_Concept
,	O
or	O
is	O
actually	O
performing	O
Input/Output	B-General_Concept
.	O
</s>
<s>
Users	O
of	O
such	O
systems	O
quickly	O
became	O
aware	O
that	O
for	O
much	O
of	O
the	O
time	O
that	O
a	O
computer	O
was	O
allocated	O
to	O
a	O
single	O
user	O
,	O
the	O
processor	B-Architecture
was	O
idle	O
;	O
when	O
the	O
user	O
was	O
entering	O
information	O
or	O
debugging	O
programs	O
for	O
example	O
.	O
</s>
<s>
Computer	B-General_Concept
scientists	I-General_Concept
observed	O
that	O
overall	O
performance	O
of	O
the	O
machine	O
could	O
be	O
improved	O
by	O
letting	O
a	O
different	O
process	B-Operating_System
use	O
the	O
processor	B-Architecture
whenever	O
one	O
process	B-Operating_System
was	O
waiting	O
for	O
input/output	B-General_Concept
.	O
</s>
<s>
In	O
a	O
uni-programming	O
system	O
,	O
if	O
N	O
users	O
were	O
to	O
execute	O
programs	O
with	O
individual	O
execution	O
times	O
of	O
t1	O
,	O
t2	O
,	O
...	O
,	O
tN	O
,	O
then	O
the	O
total	O
time	O
,	O
tuni	O
,	O
to	O
service	O
the	O
N	O
processes	B-Operating_System
(	O
consecutively	O
)	O
of	O
all	O
N	O
users	O
would	O
be	O
:	O
</s>
<s>
However	O
,	O
because	O
each	O
process	B-Operating_System
consumes	O
both	O
CPU	B-Device
cycles	O
and	O
I/O	B-General_Concept
cycles	O
,	O
the	O
time	O
which	O
each	O
process	B-Operating_System
actually	O
uses	O
the	O
CPU	B-Device
is	O
a	O
very	O
small	O
fraction	O
of	O
the	O
total	O
execution	O
time	O
for	O
the	O
process	B-Operating_System
.	O
</s>
<s>
So	O
,	O
for	O
process	B-Operating_System
i	O
:	O
</s>
<s>
ti	O
(	O
execution	O
)	O
is	O
the	O
total	O
execution	O
time	O
for	O
the	O
process	B-Operating_System
;	O
i.e.	O
</s>
<s>
the	O
time	O
for	O
CPU	B-Device
cycles	O
plus	O
I/O	B-General_Concept
cycles	O
to	O
be	O
carried	O
out	O
(	O
executed	O
)	O
until	O
completion	O
of	O
the	O
process	B-Operating_System
.	O
</s>
<s>
In	O
fact	O
,	O
usually	O
the	O
sum	O
of	O
all	O
the	O
processor	B-Architecture
time	O
,	O
used	O
by	O
N	O
processes	B-Operating_System
,	O
rarely	O
exceeds	O
a	O
small	O
fraction	O
of	O
the	O
time	O
to	O
execute	O
any	O
one	O
of	O
the	O
processes	B-Operating_System
;	O
</s>
<s>
Therefore	O
,	O
in	O
uni-programming	O
systems	O
,	O
the	O
processor	B-Architecture
lay	O
idle	O
for	O
a	O
considerable	O
proportion	O
of	O
the	O
time	O
.	O
</s>
<s>
To	O
overcome	O
this	O
inefficiency	O
,	O
multiprogramming	O
is	O
now	O
implemented	O
in	O
modern	O
operating	B-General_Concept
systems	I-General_Concept
such	O
as	O
Linux	B-Application
,	O
UNIX	B-Application
and	O
Microsoft	B-Application
Windows	I-Application
.	O
</s>
<s>
This	O
enables	O
the	O
processor	B-Architecture
to	O
switch	O
from	O
one	O
process	B-Operating_System
,	O
X	O
,	O
to	O
another	O
,	O
Y	O
,	O
whenever	O
X	O
is	O
involved	O
in	O
the	O
I/O	B-General_Concept
phase	O
of	O
its	O
execution	O
.	O
</s>
<s>
Operating	B-General_Concept
systems	I-General_Concept
need	O
some	O
ways	O
to	O
create	O
processes	B-Operating_System
.	O
</s>
<s>
In	O
a	O
very	O
simple	O
system	O
designed	O
for	O
running	O
only	O
a	O
single	O
application	B-Application
(	O
e.g.	O
,	O
the	O
controller	O
in	O
a	O
microwave	O
oven	O
)	O
,	O
it	O
may	O
be	O
possible	O
to	O
have	O
all	O
the	O
processes	B-Operating_System
that	O
will	O
ever	O
be	O
needed	O
be	O
present	O
when	O
the	O
system	O
comes	O
up	O
.	O
</s>
<s>
In	O
general-purpose	O
systems	O
,	O
however	O
,	O
some	O
way	O
is	O
needed	O
to	O
create	O
and	O
terminate	O
processes	B-Operating_System
as	O
needed	O
during	O
operation	O
.	O
</s>
<s>
There	O
are	O
four	O
principal	O
events	O
that	O
cause	O
a	O
process	B-Operating_System
to	O
be	O
created	O
:	O
</s>
<s>
Execution	O
of	O
process	B-Operating_System
creation	O
system	B-Operating_System
call	I-Operating_System
by	O
a	O
running	O
process	B-Operating_System
.	O
</s>
<s>
A	O
user	O
request	O
to	O
create	O
a	O
new	O
process	B-Operating_System
.	O
</s>
<s>
When	O
an	O
operating	B-General_Concept
system	I-General_Concept
is	O
booted	O
,	O
typically	O
several	O
processes	B-Operating_System
are	O
created	O
.	O
</s>
<s>
Some	O
of	O
these	O
are	O
foreground	O
processes	B-Operating_System
,	O
that	O
interact	O
with	O
a	O
(	O
human	O
)	O
user	O
and	O
perform	O
work	O
for	O
them	O
.	O
</s>
<s>
Others	O
are	O
background	B-Operating_System
processes	I-Operating_System
,	O
which	O
are	O
not	O
associated	O
with	O
particular	O
users	O
,	O
but	O
instead	O
have	O
some	O
specific	O
function	O
.	O
</s>
<s>
For	O
example	O
,	O
one	O
background	B-Operating_System
process	I-Operating_System
may	O
be	O
designed	O
to	O
accept	O
incoming	O
e-mails	O
,	O
sleeping	O
most	O
of	O
the	O
day	O
but	O
suddenly	O
springing	O
to	O
life	O
when	O
an	O
incoming	O
e-mail	O
arrives	O
.	O
</s>
<s>
Another	O
background	B-Operating_System
process	I-Operating_System
may	O
be	O
designed	O
to	O
accept	O
an	O
incoming	O
request	O
for	O
web	O
pages	O
hosted	O
on	O
the	O
machine	O
,	O
waking	O
up	O
when	O
a	O
request	O
arrives	O
to	O
service	O
that	O
request	O
.	O
</s>
<s>
Process	B-Operating_System
creation	O
in	O
UNIX	B-Application
and	O
Linux	B-Application
are	O
done	O
through	O
fork( )	O
or	O
clone( )	O
system	B-Operating_System
calls	I-Operating_System
.	O
</s>
<s>
There	O
are	O
several	O
steps	O
involved	O
in	O
process	B-Operating_System
creation	O
.	O
</s>
<s>
The	O
first	O
step	O
is	O
the	O
validation	O
of	O
whether	O
the	O
parent	B-Operating_System
process	I-Operating_System
has	O
sufficient	O
authorization	O
to	O
create	O
a	O
process	B-Operating_System
.	O
</s>
<s>
Upon	O
successful	O
validation	O
,	O
the	O
parent	B-Operating_System
process	I-Operating_System
is	O
copied	O
almost	O
entirely	O
,	O
with	O
changes	O
only	O
to	O
the	O
unique	O
process	B-Operating_System
id	O
,	O
parent	B-Operating_System
process	I-Operating_System
,	O
and	O
user-space	B-Operating_System
.	O
</s>
<s>
Each	O
new	O
process	B-Operating_System
gets	O
its	O
own	O
user	B-Operating_System
space	I-Operating_System
.	O
</s>
<s>
Process	B-Operating_System
creation	O
in	O
Windows	O
is	O
done	O
through	O
the	O
CreateProcessA( )	O
system	B-Operating_System
call	I-Operating_System
.	O
</s>
<s>
A	O
new	O
process	B-Operating_System
runs	O
in	O
the	O
security	O
context	O
of	O
the	O
calling	O
process	B-Operating_System
,	O
but	O
otherwise	O
runs	O
independently	O
of	O
the	O
calling	O
process	B-Operating_System
.	O
</s>
<s>
Methods	O
exist	O
to	O
alter	O
the	O
security	O
context	O
in	O
which	O
a	O
new	O
processes	B-Operating_System
runs	O
.	O
</s>
<s>
New	O
processes	B-Operating_System
are	O
assigned	O
identifiers	O
by	O
which	O
the	O
can	O
be	O
accessed	O
.	O
</s>
<s>
Functions	O
are	O
provided	O
to	O
synchronize	O
calling	O
threads	B-Operating_System
to	O
newly	O
created	O
processes	B-Operating_System
.	O
</s>
<s>
There	O
are	O
many	O
reasons	O
for	O
process	B-Operating_System
termination	O
:	O
</s>
<s>
The	O
operating	B-General_Concept
system	I-General_Concept
’s	O
principal	O
responsibility	O
is	O
in	O
controlling	O
the	O
execution	O
of	O
processes	B-Operating_System
.	O
</s>
<s>
This	O
includes	O
determining	O
the	O
interleaving	O
pattern	O
for	O
execution	O
and	O
allocation	O
of	O
resources	O
to	O
processes	B-Operating_System
.	O
</s>
<s>
One	O
part	O
of	O
designing	O
an	O
OS	B-General_Concept
is	O
to	O
describe	O
the	O
behaviour	O
that	O
we	O
would	O
like	O
each	O
process	B-Operating_System
to	O
exhibit	O
.	O
</s>
<s>
The	O
simplest	O
model	O
is	O
based	O
on	O
the	O
fact	O
that	O
a	O
process	B-Operating_System
is	O
either	O
being	O
executed	O
by	O
a	O
processor	B-Architecture
or	O
it	O
is	O
not	O
.	O
</s>
<s>
Thus	O
,	O
a	O
process	B-Operating_System
may	O
be	O
considered	O
to	O
be	O
in	O
one	O
of	O
two	O
states	O
,	O
RUNNING	O
or	O
NOT	O
RUNNING	O
.	O
</s>
<s>
When	O
the	O
operating	B-General_Concept
system	I-General_Concept
creates	O
a	O
new	O
process	B-Operating_System
,	O
that	O
process	B-Operating_System
is	O
initially	O
labeled	O
as	O
NOT	O
RUNNING	O
,	O
and	O
is	O
placed	O
into	O
a	O
queue	O
in	O
the	O
system	O
in	O
the	O
NOT	O
RUNNING	O
state	O
.	O
</s>
<s>
The	O
process	B-Operating_System
(	O
or	O
some	O
portion	O
of	O
it	O
)	O
then	O
exists	O
in	O
main	O
memory	O
,	O
and	O
it	O
waits	O
in	O
the	O
queue	O
for	O
an	O
opportunity	O
to	O
be	O
executed	O
.	O
</s>
<s>
After	O
some	O
period	O
of	O
time	O
,	O
the	O
currently	O
RUNNING	O
process	B-Operating_System
will	O
be	O
interrupted	O
,	O
and	O
moved	O
from	O
the	O
RUNNING	O
state	O
to	O
the	O
NOT	O
RUNNING	O
state	O
,	O
making	O
the	O
processor	B-Architecture
available	O
for	O
a	O
different	O
process	B-Operating_System
.	O
</s>
<s>
The	O
dispatch	O
portion	O
of	O
the	O
OS	B-General_Concept
will	O
then	O
select	O
,	O
from	O
the	O
queue	O
of	O
NOT	O
RUNNING	O
processes	B-Operating_System
,	O
one	O
of	O
the	O
waiting	O
processes	B-Operating_System
to	O
transfer	O
to	O
the	O
processor	B-Architecture
.	O
</s>
<s>
The	O
chosen	O
process	B-Operating_System
is	O
then	O
relabeled	O
from	O
a	O
NOT	O
RUNNING	O
state	O
to	O
a	O
RUNNING	O
state	O
,	O
and	O
its	O
execution	O
is	O
either	O
begun	O
if	O
it	O
is	O
a	O
new	O
process	B-Operating_System
,	O
or	O
is	O
resumed	O
if	O
it	O
is	O
a	O
process	B-Operating_System
which	O
was	O
interrupted	O
at	O
an	O
earlier	O
time	O
.	O
</s>
<s>
From	O
this	O
model	O
we	O
can	O
identify	O
some	O
design	O
elements	O
of	O
the	O
OS	B-General_Concept
:	O
</s>
<s>
The	O
need	O
to	O
represent	O
,	O
and	O
keep	O
track	O
of	O
each	O
process	B-Operating_System
.	O
</s>
<s>
The	O
state	O
of	O
a	O
process	B-Operating_System
.	O
</s>
<s>
Although	O
the	O
two-state	O
process	B-Operating_System
management	I-Operating_System
model	O
is	O
a	O
perfectly	O
valid	O
design	O
for	O
an	O
operating	B-General_Concept
system	I-General_Concept
,	O
the	O
absence	O
of	O
a	O
BLOCKED	O
state	O
means	O
that	O
the	O
processor	B-Architecture
lies	O
idle	O
when	O
the	O
active	O
process	B-Operating_System
changes	O
from	O
CPU	B-Device
cycles	O
to	O
I/O	B-General_Concept
cycles	O
.	O
</s>
<s>
This	O
design	O
does	O
not	O
make	O
efficient	O
use	O
of	O
the	O
processor	B-Architecture
.	O
</s>
<s>
The	O
three-state	O
process	B-Operating_System
management	I-Operating_System
model	O
is	O
designed	O
to	O
overcome	O
this	O
problem	O
,	O
by	O
introducing	O
a	O
new	O
state	O
called	O
the	O
BLOCKED	O
state	O
.	O
</s>
<s>
This	O
state	O
describes	O
any	O
process	B-Operating_System
which	O
is	O
waiting	O
for	O
an	O
I/O	B-General_Concept
event	O
to	O
take	O
place	O
.	O
</s>
<s>
In	O
this	O
case	O
,	O
an	O
I/O	B-General_Concept
event	O
can	O
mean	O
the	O
use	O
of	O
some	O
device	O
or	O
a	O
signal	O
from	O
another	O
process	B-Operating_System
.	O
</s>
<s>
RUNNING	O
:	O
The	O
process	B-Operating_System
that	O
is	O
currently	O
being	O
executed	O
.	O
</s>
<s>
READY	O
:	O
A	O
process	B-Operating_System
that	O
is	O
queuing	O
and	O
prepared	O
to	O
execute	O
when	O
given	O
the	O
opportunity	O
.	O
</s>
<s>
BLOCKED	O
:	O
A	O
process	B-Operating_System
that	O
cannot	O
execute	O
until	O
some	O
event	O
occurs	O
,	O
such	O
as	O
the	O
completion	O
of	O
an	O
I/O	B-General_Concept
operation	I-General_Concept
.	O
</s>
<s>
At	O
any	O
instant	O
,	O
a	O
process	B-Operating_System
is	O
in	O
one	O
and	O
only	O
one	O
of	O
the	O
three	O
states	O
.	O
</s>
<s>
For	O
a	O
single	O
processor	B-Architecture
computer	O
,	O
only	O
one	O
process	B-Operating_System
can	O
be	O
in	O
the	O
RUNNING	O
state	O
at	O
any	O
one	O
instant	O
.	O
</s>
<s>
There	O
can	O
be	O
many	O
processes	B-Operating_System
in	O
the	O
READY	O
and	O
BLOCKED	O
states	O
,	O
and	O
each	O
of	O
these	O
states	O
will	O
have	O
an	O
associated	O
queue	O
for	O
processes	B-Operating_System
.	O
</s>
<s>
Processes	B-Operating_System
entering	O
the	O
system	O
must	O
go	O
initially	O
into	O
the	O
READY	O
state	O
,	O
processes	B-Operating_System
can	O
only	O
enter	O
the	O
RUNNING	O
state	O
via	O
the	O
READY	O
state	O
.	O
</s>
<s>
Processes	B-Operating_System
normally	O
leave	O
the	O
system	O
from	O
the	O
RUNNING	O
state	O
.	O
</s>
<s>
For	O
each	O
of	O
the	O
three	O
states	O
,	O
the	O
process	B-Operating_System
occupies	O
space	O
in	O
main	O
memory	O
.	O
</s>
<s>
RUNNING	O
→	O
READY	O
The	O
most	O
common	O
reason	O
for	O
this	O
transition	O
is	O
that	O
the	O
running	O
process	B-Operating_System
has	O
reached	O
the	O
maximum	O
allowable	O
time	O
for	O
uninterrupted	O
execution	O
;	O
i.e.	O
</s>
<s>
Other	O
reasons	O
can	O
be	O
the	O
imposition	O
of	O
priority	O
levels	O
as	O
determined	O
by	O
the	O
scheduling	O
policy	O
used	O
for	O
the	O
Low	O
Level	O
Scheduler	O
,	O
and	O
the	O
arrival	O
of	O
a	O
higher	O
priority	O
process	B-Operating_System
into	O
the	O
READY	O
state	O
.	O
</s>
<s>
RUNNING	O
→	O
BLOCKED	O
A	O
process	B-Operating_System
is	O
put	O
into	O
the	O
BLOCKED	O
state	O
if	O
it	O
requests	O
something	O
for	O
which	O
it	O
must	O
wait	O
.	O
</s>
<s>
A	O
request	O
to	O
the	O
OS	B-General_Concept
is	O
usually	O
in	O
the	O
form	O
of	O
a	O
system	B-Operating_System
call	I-Operating_System
,	O
(	O
i.e.	O
</s>
<s>
a	O
call	O
from	O
the	O
running	O
process	B-Operating_System
to	O
a	O
function	O
that	O
is	O
part	O
of	O
the	O
OS	B-General_Concept
code	O
)	O
.	O
</s>
<s>
Each	O
process	B-Operating_System
in	O
the	O
system	O
is	O
represented	O
by	O
a	O
data	B-General_Concept
structure	I-General_Concept
called	O
a	O
Process	B-Operating_System
Control	I-Operating_System
Block	I-Operating_System
(	O
PCB	O
)	O
,	O
or	O
Process	B-Operating_System
Descriptor	O
in	O
Linux	B-Application
,	O
which	O
performs	O
the	O
same	O
function	O
as	O
a	O
traveller	O
's	O
passport	O
.	O
</s>
<s>
Process	B-Operating_System
Identification	O
:	O
Each	O
process	B-Operating_System
is	O
uniquely	O
identified	O
by	O
the	O
user	O
’s	O
identification	O
and	O
a	O
pointer	O
connecting	O
it	O
to	O
its	O
descriptor	O
.	O
</s>
<s>
Process	B-Operating_System
Status	O
:	O
This	O
indicates	O
the	O
current	O
status	O
of	O
the	O
process	B-Operating_System
;	O
</s>
<s>
Process	B-Operating_System
State	O
:	O
This	O
contains	O
all	O
of	O
the	O
information	O
needed	O
to	O
indicate	O
the	O
current	O
state	O
of	O
the	O
job	O
.	O
</s>
<s>
It	O
indicates	O
what	O
kind	O
of	O
resources	O
the	O
process	B-Operating_System
has	O
used	O
and	O
for	O
how	O
long	O
.	O
</s>
<s>
Contemporary	O
processors	O
incorporate	O
a	O
mode	O
bit	O
to	O
define	O
the	O
execution	O
capability	O
of	O
a	O
program	B-Application
in	O
the	O
processor	B-Architecture
.	O
</s>
<s>
This	O
bit	O
can	O
be	O
set	O
to	O
kernel	B-Operating_System
mode	O
or	O
user	B-Operating_System
mode	I-Operating_System
.	O
</s>
<s>
Kernel	B-Operating_System
mode	O
is	O
also	O
commonly	O
referred	O
to	O
as	O
supervisor	O
mode	O
,	O
monitor	O
mode	O
or	O
ring	B-Operating_System
0	I-Operating_System
.	O
</s>
<s>
In	O
kernel	B-Operating_System
mode	O
,	O
the	O
processor	B-Architecture
can	O
execute	O
every	O
instruction	O
in	O
its	O
hardware	O
repertoire	O
,	O
whereas	O
in	O
user	B-Operating_System
mode	I-Operating_System
,	O
it	O
can	O
only	O
execute	O
a	O
subset	O
of	O
the	O
instructions	O
.	O
</s>
<s>
Instructions	O
that	O
can	O
be	O
executed	O
only	O
in	O
kernel	B-Operating_System
mode	O
are	O
called	O
kernel	B-Operating_System
,	O
privileged	O
or	O
protected	O
instructions	O
to	O
distinguish	O
them	O
from	O
the	O
user	B-Operating_System
mode	I-Operating_System
instructions	O
.	O
</s>
<s>
For	O
example	O
,	O
I/O	B-General_Concept
instructions	O
are	O
privileged	O
.	O
</s>
<s>
So	O
,	O
if	O
an	O
application	B-Application
program	I-Application
executes	O
in	O
user	B-Operating_System
mode	I-Operating_System
,	O
it	O
cannot	O
perform	O
its	O
own	O
I/O	B-General_Concept
.	O
</s>
<s>
Instead	O
,	O
it	O
must	O
request	O
the	O
OS	B-General_Concept
to	O
perform	O
I/O	B-General_Concept
on	O
its	O
behalf	O
.	O
</s>
<s>
The	O
computer	B-General_Concept
architecture	I-General_Concept
may	O
logically	O
extend	O
the	O
mode	O
bit	O
to	O
define	O
areas	O
of	O
memory	O
to	O
be	O
used	O
when	O
the	O
processor	B-Architecture
is	O
in	O
kernel	B-Operating_System
mode	O
versus	O
user	B-Operating_System
mode	I-Operating_System
.	O
</s>
<s>
If	O
the	O
mode	O
bit	O
is	O
set	O
to	O
kernel	B-Operating_System
mode	O
,	O
the	O
process	B-Operating_System
executing	O
in	O
the	O
processor	B-Architecture
can	O
access	O
either	O
the	O
kernel	B-Operating_System
or	O
user	O
partition	O
of	O
the	O
memory	O
.	O
</s>
<s>
However	O
,	O
if	O
user	B-Operating_System
mode	I-Operating_System
is	O
set	O
,	O
the	O
process	B-Operating_System
can	O
reference	O
only	O
the	O
user	O
memory	O
space	O
.	O
</s>
<s>
We	O
frequently	O
refer	O
to	O
two	O
classes	O
of	O
memory	O
user	B-Operating_System
space	I-Operating_System
and	O
system	O
space	O
(	O
or	O
kernel	B-Operating_System
,	O
supervisor	O
or	O
protected	O
space	O
)	O
.	O
</s>
<s>
In	O
general	O
,	O
the	O
mode	O
bit	O
extends	O
the	O
operating	B-General_Concept
system	I-General_Concept
's	O
protection	O
rights	O
.	O
</s>
<s>
The	O
mode	O
bit	O
is	O
set	O
by	O
the	O
user	B-Operating_System
mode	I-Operating_System
trap	B-Application
instruction	O
,	O
also	O
called	O
a	O
Supervisor	B-Operating_System
Call	I-Operating_System
instruction	I-Operating_System
.	O
</s>
<s>
Since	O
only	O
system	O
code	O
is	O
loaded	O
in	O
the	O
system	O
space	O
,	O
only	O
system	O
code	O
can	O
be	O
invoked	O
via	O
a	O
trap	B-Application
.	O
</s>
<s>
When	O
the	O
OS	B-General_Concept
has	O
completed	O
the	O
supervisor	B-Operating_System
call	I-Operating_System
,	O
it	O
resets	O
the	O
mode	O
bit	O
to	O
user	B-Operating_System
mode	I-Operating_System
prior	O
to	O
the	O
return	O
.	O
</s>
<s>
The	O
parts	O
of	O
the	O
OS	B-General_Concept
critical	O
to	O
its	O
correct	O
operation	O
execute	O
in	O
kernel	B-Operating_System
mode	O
,	O
while	O
other	O
software	O
(	O
such	O
as	O
generic	O
system	B-Application
software	I-Application
)	O
and	O
all	O
application	B-Application
programs	I-Application
execute	O
in	O
user	B-Operating_System
mode	I-Operating_System
.	O
</s>
<s>
This	O
fundamental	O
distinction	O
is	O
usually	O
the	O
irrefutable	O
distinction	O
between	O
the	O
operating	B-General_Concept
system	I-General_Concept
and	O
other	O
system	B-Application
software	I-Application
.	O
</s>
<s>
The	O
part	O
of	O
the	O
system	O
executing	O
in	O
kernel	B-Operating_System
supervisor	O
state	O
is	O
called	O
the	O
kernel	B-Operating_System
,	O
or	O
nucleus	B-Operating_System
,	O
of	O
the	O
operating	B-General_Concept
system	I-General_Concept
.	O
</s>
<s>
The	O
kernel	B-Operating_System
operates	O
as	O
trusted	O
software	O
,	O
meaning	O
that	O
when	O
it	O
was	O
designed	O
and	O
implemented	O
,	O
it	O
was	O
intended	O
to	O
implement	O
protection	O
mechanisms	O
that	O
could	O
not	O
be	O
covertly	O
changed	O
through	O
the	O
actions	O
of	O
untrusted	O
software	O
executing	O
in	O
user	B-Operating_System
space	I-Operating_System
.	O
</s>
<s>
Extensions	O
to	O
the	O
OS	B-General_Concept
execute	O
in	O
user	B-Operating_System
mode	I-Operating_System
,	O
so	O
the	O
OS	B-General_Concept
does	O
not	O
rely	O
on	O
the	O
correctness	O
of	O
those	O
parts	O
of	O
the	O
system	B-Application
software	I-Application
for	O
correct	O
operation	O
of	O
the	O
OS	B-General_Concept
.	O
</s>
<s>
Hence	O
,	O
a	O
fundamental	O
design	O
decision	O
for	O
any	O
function	O
to	O
be	O
incorporated	O
into	O
the	O
OS	B-General_Concept
is	O
whether	O
it	O
needs	O
to	O
be	O
implemented	O
in	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
If	O
it	O
is	O
implemented	O
in	O
the	O
kernel	B-Operating_System
,	O
it	O
will	O
execute	O
in	O
kernel	B-Operating_System
(	O
supervisor	O
)	O
space	O
,	O
and	O
have	O
access	O
to	O
other	O
parts	O
of	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
It	O
will	O
also	O
be	O
trusted	O
software	O
by	O
the	O
other	O
parts	O
of	O
the	O
kernel	B-Operating_System
.	O
</s>
<s>
If	O
the	O
function	O
is	O
implemented	O
to	O
execute	O
in	O
user	B-Operating_System
mode	I-Operating_System
,	O
it	O
will	O
have	O
no	O
access	O
to	O
kernel	B-Operating_System
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
While	O
kernel-implemented	O
functions	O
may	O
be	O
easy	O
to	O
implement	O
,	O
the	O
trap	B-Application
mechanism	O
and	O
authentication	O
at	O
the	O
time	O
of	O
the	O
call	O
are	O
usually	O
relatively	O
expensive	O
.	O
</s>
<s>
The	O
kernel	B-Operating_System
code	O
runs	O
fast	O
,	O
but	O
there	O
is	O
a	O
large	O
performance	O
overhead	O
in	O
the	O
actual	O
call	O
.	O
</s>
<s>
There	O
are	O
two	O
techniques	O
by	O
which	O
a	O
program	B-Application
executing	O
in	O
user	B-Operating_System
mode	I-Operating_System
can	O
request	O
the	O
kernel	B-Operating_System
's	O
services	O
:	O
</s>
<s>
Operating	B-General_Concept
systems	I-General_Concept
are	O
designed	O
with	O
one	O
or	O
the	O
other	O
of	O
these	O
two	O
facilities	O
,	O
but	O
not	O
both	O
.	O
</s>
<s>
First	O
,	O
assume	O
that	O
a	O
user	B-Operating_System
process	I-Operating_System
wishes	O
to	O
invoke	O
a	O
particular	O
target	O
system	O
function	O
.	O
</s>
<s>
For	O
the	O
system	B-Operating_System
call	I-Operating_System
approach	O
,	O
the	O
user	B-Operating_System
process	I-Operating_System
uses	O
the	O
trap	B-Application
instruction	O
.	O
</s>
<s>
The	O
idea	O
is	O
that	O
the	O
system	B-Operating_System
call	I-Operating_System
should	O
appear	O
to	O
be	O
an	O
ordinary	O
procedure	O
call	O
to	O
the	O
application	B-Application
program	I-Application
;	O
the	O
OS	B-General_Concept
provides	O
a	O
library	O
of	O
user	O
functions	O
with	O
names	O
corresponding	O
to	O
each	O
actual	O
system	B-Operating_System
call	I-Operating_System
.	O
</s>
<s>
Each	O
of	O
these	O
stub	O
functions	O
contains	O
a	O
trap	B-Application
to	O
the	O
OS	B-General_Concept
function	O
.	O
</s>
<s>
When	O
the	O
application	B-Application
program	I-Application
calls	O
the	O
stub	O
,	O
it	O
executes	O
the	O
trap	B-Application
instruction	O
,	O
which	O
switches	O
the	O
CPU	B-Device
to	O
kernel	B-Operating_System
mode	O
,	O
and	O
then	O
branches	O
(	O
indirectly	O
through	O
an	O
OS	B-General_Concept
table	O
)	O
,	O
to	O
the	O
entry	O
point	O
of	O
the	O
function	O
which	O
is	O
to	O
be	O
invoked	O
.	O
</s>
<s>
When	O
the	O
function	O
completes	O
,	O
it	O
switches	O
the	O
processor	B-Architecture
to	O
user	B-Operating_System
mode	I-Operating_System
and	O
then	O
returns	O
control	O
to	O
the	O
user	B-Operating_System
process	I-Operating_System
;	O
thus	O
simulating	O
a	O
normal	O
procedure	O
return	O
.	O
</s>
<s>
In	O
the	O
message	B-Architecture
passing	I-Architecture
approach	O
,	O
the	O
user	B-Operating_System
process	I-Operating_System
constructs	O
a	O
message	O
,	O
that	O
describes	O
the	O
desired	O
service	O
.	O
</s>
<s>
Then	O
it	O
uses	O
a	O
trusted	O
send	O
function	O
to	O
pass	O
the	O
message	O
to	O
a	O
trusted	O
OS	B-General_Concept
process	B-Operating_System
.	O
</s>
<s>
The	O
send	O
function	O
serves	O
the	O
same	O
purpose	O
as	O
the	O
trap	B-Application
;	O
that	O
is	O
,	O
it	O
carefully	O
checks	O
the	O
message	O
,	O
switches	O
the	O
processor	B-Architecture
to	O
kernel	B-Operating_System
mode	O
,	O
and	O
then	O
delivers	O
the	O
message	O
to	O
a	O
process	B-Operating_System
that	O
implements	O
the	O
target	O
functions	O
.	O
</s>
<s>
Meanwhile	O
,	O
the	O
user	B-Operating_System
process	I-Operating_System
waits	O
for	O
the	O
result	O
of	O
the	O
service	O
request	O
with	O
a	O
message	O
receive	O
operation	O
.	O
</s>
<s>
When	O
the	O
OS	B-General_Concept
process	B-Operating_System
completes	O
the	O
operation	O
,	O
it	O
sends	O
a	O
message	O
back	O
to	O
the	O
user	B-Operating_System
process	I-Operating_System
.	O
</s>
<s>
The	O
distinction	O
between	O
two	O
approaches	O
has	O
important	O
consequences	O
regarding	O
the	O
relative	O
independence	O
of	O
the	O
OS	B-General_Concept
behavior	O
,	O
from	O
the	O
application	B-Application
process	B-Operating_System
behavior	O
,	O
and	O
the	O
resulting	O
performance	O
.	O
</s>
<s>
As	O
a	O
rule	O
of	O
thumb	O
,	O
operating	B-General_Concept
system	I-General_Concept
based	O
on	O
a	O
system	B-Operating_System
call	I-Operating_System
interface	O
can	O
be	O
made	O
more	O
efficient	O
than	O
those	O
requiring	O
messages	O
to	O
be	O
exchanged	O
between	O
distinct	O
processes	B-Operating_System
.	O
</s>
<s>
This	O
is	O
the	O
case	O
,	O
even	O
though	O
the	O
system	B-Operating_System
call	I-Operating_System
must	O
be	O
implemented	O
with	O
a	O
trap	B-Application
instruction	O
;	O
that	O
is	O
,	O
even	O
though	O
the	O
trap	B-Application
is	O
relatively	O
expensive	O
to	O
perform	O
,	O
it	O
is	O
more	O
efficient	O
than	O
the	O
message	B-Architecture
passing	I-Architecture
approach	O
,	O
where	O
there	O
are	O
generally	O
higher	O
costs	O
associated	O
with	O
process	B-Operating_System
multiplexing	B-Architecture
,	O
message	O
formation	O
and	O
message	O
copying	O
.	O
</s>
<s>
The	O
system	B-Operating_System
call	I-Operating_System
approach	O
has	O
the	O
interesting	O
property	O
that	O
there	O
is	O
not	O
necessarily	O
any	O
OS	B-General_Concept
process	B-Operating_System
.	O
</s>
<s>
Instead	O
,	O
a	O
process	B-Operating_System
executing	O
in	O
user	B-Operating_System
mode	I-Operating_System
changes	O
to	O
kernel	B-Operating_System
mode	O
when	O
it	O
is	O
executing	O
kernel	B-Operating_System
code	O
,	O
and	O
switches	O
back	O
to	O
user	B-Operating_System
mode	I-Operating_System
when	O
it	O
returns	O
from	O
the	O
OS	B-General_Concept
call	O
.	O
</s>
<s>
If	O
,	O
on	O
the	O
other	O
hand	O
,	O
the	O
OS	B-General_Concept
is	O
designed	O
as	O
a	O
set	O
of	O
separate	O
processes	B-Operating_System
,	O
it	O
is	O
usually	O
easier	O
to	O
design	O
it	O
so	O
that	O
it	O
gets	O
control	O
of	O
the	O
machine	O
in	O
special	O
situations	O
,	O
than	O
if	O
the	O
kernel	B-Operating_System
is	O
simply	O
a	O
collection	O
of	O
functions	O
executed	O
by	O
users	O
processes	B-Operating_System
in	O
kernel	B-Operating_System
mode	O
.	O
</s>
<s>
Even	O
procedure-based	O
operating	B-General_Concept
system	I-General_Concept
usually	O
find	O
it	O
necessary	O
to	O
include	O
at	O
least	O
a	O
few	O
system	O
processes	B-Operating_System
(	O
called	O
daemons	B-Operating_System
in	O
UNIX	B-Application
)	O
to	O
handle	O
situation	O
whereby	O
the	O
machine	O
is	O
otherwise	O
idle	O
such	O
as	O
scheduling	O
and	O
handling	O
the	O
network	O
.	O
</s>
