Sie sind auf Seite 1von 61

Chapter 3

Processes
|
'& Strathmore

Objectives
., UNIVERSITY
'tii.iidI'

• To explain the notion of a process in


operating systems

• To describe the various features of


processes

• To describe operations on processes

|
'& Strathmor
Chapter 3: Processes .,
'tii.iidI'
e
UNIVERSITY

• Process Concept
– What is a process?
– What are the components of a process?
– What are the differences between a program and a process?
– How does the operating system manage processes?

• Operations on Processes

• Communication in Client-Server
Systems

|
Introduction
'& Strathmore
., UNIVERSITY
'tii.iidI'

• Early computer systems allowed only


one program to be executed at a
time. This program had complete
control of the system and had access
to all the system's resources.

|
Introduction '&
.,
'tii.iidI'
Strathmore
UNIVERSITY

• In contrast, current-day computer


systems allow multiple programs to
be loaded into memory and executed
concurrently.(multiprocessing/times
haring)

|
'&
Process Concept
Strathmor
., e
'tii.iidI'
UNIVERSITY

• Process – a program in execution

|
'& Strathmor

The Process
., e
'tii.iidI'
UNIVERSITY

ax
sac

h a

ex

|
'& Strathmore

The Process .,
'tii.iidI'
UNIVERSITY

• A process is more than the program code,


which is sometimes known as the text
section. It consists of Multiple parts;

1. Text section-The object program to be


executed (
• 2. Current activity-represented by the
value of the program counter

|
'& Strathmor

The Process
., e
'tii.iidI'
UNIVERSITY

3. The data on which the program will


execute

4.Resources required by the program ( for


example, files containing requisite
information)

5. Stack: Temporary data example local


variables
|
'& Strathmore
., UNIVERSITY
'tii.iidI'

What is the difference between a program and a


process?

|
'& Strathmore

Differences between a program and a process?


., UNIVERSITY
'tii .iid I'

• Program is passive entity(an executable


file), process is active
– Program becomes process when executable file loaded
into memory

• One program can have several processes.


How?
– Consider multiple users executing the same program

|
'& Strathmore
Difference between a program and a proce s s?
.,
'tii.iidI'
UNIVERSITY

• Two processes may be associated with the


same program, they are nevertheless
considered two separate execution
sequences.

|
'& Strathmore
Difference between a program and a proce s s?
.,
'tii.iidI'
UNIVERSITY

For instance, several users may be running


different copies of the mail program, or the
same user may invoke many copies of the web
browser program. Each of these is a separate
process; and although the text sections are
equivalent, the data, heap (memory allocated),
and stack sections vary.

|
'& Strathmor
Process State .,
'tii.iidI'
e
UNIVERSITY

• As a process executes, it changes


state. Each process may be in one of
the following states:

|
'&
Diagram of Process State
Strathmor
., e
'tii.iidI'
UNIVERSITY

ne interr
w upt

rea runni
dy ng

I/O or event I/O event


completion or wait
waiti
ng

|
'& Strathmore
Process State .,
'tii.iidI'
UNIVERSITY

– new: The process is being created


– ready: The process is waiting to
be assigned to a processor
– waiting: The process is waiting for
some event to occur
– running: Instructions are being
executed
– terminated: The process has
finished execution
|
Strathmor
e
Class Exercise UNIVERSITY

Using the process diagram aam inter


discussed, attempt the following ittea r~~t
questions
1. Distinguish between a process
that is in the waiting state and
a process in the ready state.
2. Identify and describe three
instances when a scheduler
dispatch occurs
3. Identify four instances when an
interrupt would occur

|
'&
Process Control Block (PCB)
Strathmor
., e
'tii.iidI'
UNIVERSITY

• Each process is represented in the


operating system by a process
control block (PCB)—also called a
task control block.
The PCB simply serves as the
repository for any information that
may vary from process to process.

|
'& Strathmor
Process Control Block (PCB) .,
'tii.iidI'
e
UNIVERSITY

Information associated with each process

• Process state (new, ready, running, waiting)

• Unique identification of the process

• Pointer to parent/child process

• CPU scheduling information (process priority)

• Memory-management information

• Accounting information-CPU time used


• I/O status information

|
III Strathmore
Process Control Block (PCB) .,
~
UNIVERSITY

proce state
ss numb
proces
er
s
count
progra
registe
er
rs
m
memo limit
ry s
list of file
open s
• ••

|
Process Scheduling

|
'& Strathmor
Process Scheduling .,
'tii.iidI'
e
UNIVERSITY

• The objective of
multiprogramming is to have some
process running at all times, in
order to maximize CPU utilization

|
'& Strathmore
Process Scheduling .,
'tii.iidI'
UNIVERSITY

• The objective of time sharing is to


switch the CPU among processes so
frequently that users can interact
with each program while it is
running

|
'& Strathmore
Process Scheduling .,
'tii.iidI'
UNIVERSITY

• Process scheduler selects among


available processes for next
execution on CPU

|
Scheduling Queues
'& Strathmore
., UNIVERSITY
'tii.iidI'

• As processes enter the system, they are


put into a job queue, which consists of
all processes in the system.

• The processes that are residing in main


memory and are ready and waiting to
execute are kept on a list called the
ready queue.
|
Scheduling Queues
'& Strathmor
., e
'tii.iidI'
UNIVERSITY

• This queue is generally stored as a


linked list. A ready-queue header
contains pointers to the first and final
PCBs in the list. Each PCB includes a
pointer field that points to the next
PCB in the ready queue.

|
Schedulers '&
.,
Strathmore
UNIVERSITY
'tii.iidI'

• A process migrates among various


scheduling queues throughout its
lifetime. Why?

|
Schedulers '&
.,
Strathmor
e
'tii.iidI'
UNIVERSITY

ne interr
w upt

rea runni
dy ng

I/O or event I/O event


completion or wait
waiti
ng

|
Schedulers '&
.,
Strathmore
UNIVERSITY
'tii.iidI'

• Long-term scheduler (or job


scheduler) – selects which processes
should be brought into the ready
queue

|
Schedulers '&
.,
Strathmore
UNIVERSITY
'tii.iidI'

• Short-term scheduler (or CPU


scheduler) – selects which process
should be executed next and
allocates CPU

– Sometimes the only scheduler in a


system

|
Schedulers (Cont.) '&
.,
Strathmore
'tii.iidI'
UNIVERSITY

• 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 controls the


degree of multiprogramming…???

|
I/O Bound/ CPU bound '&
.,
Strathmor
e

processes
'tii.iidI'
UNIVERSITY

• Processes can be described as either:


– I/O-bound process – spends more
time doing I/O than computations,
many short CPU bursts. Example
interactive processes.
– CPU-bound process – spends more
time doing computations; few very
long CPU bursts

|
I/O Bound/ CPU bound '&
.,
Strathmore
UNIVERSITY

processes
'tii.iidI'

• It is important that the long-term


scheduler select a good process mix
of I/O-bound and CPU-bound

• What is the outcome if all processes


are I/O bound?

|
Addition of Medium Term '& Strathmor
e
Scheduling
.,
'tii.iidI'
UNIVERSITY

Time-sharing systems, may introduce


an additional, intermediate level of
scheduling.
The medium-term scheduler.

|
'& Strathmor
Addition of Medium Term Scheduling .,
'tii.iidI'
e
UNIVERSITY

sw I partially swa
ap n executed
swapp proce p out
ed-out sses

'"
----- ready I-~~~ C ' - e
--~ ~I......---""'"
queue P -~ n
U d

~II/O~~ 1/0 1

~ waiti
ng
que
ues |
Addition of Medium Term '& Strathmor
e
Scheduling
.,
'tii.iidI'
UNIVERSITY

The medium-term scheduler


swaps process in and out of the
CPU.
Swapping may be necessary to
improve the process mix

|
'& Strathmore

Context Switch
., UNIVERSITY
'tii.iidI'

• When an interrupt occurs, the system


needs to save the current context of
the process currently running on
the CPU so that it can restore that
context when its processing is done,
essentially suspending the process
and then resuming it.

|
'& Strathmor

Context Switch
., e
'tii.iidI'
UNIVERSITY

• 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.

• Where is the context represented?

|
Operations on Processes '&
.,
'tii.iidI'
Strathmor
e
UNIVERSITY

1.Process Creation

2.Process Termination

3.Inter-process communication

|
Process Creation '&
.,
'tii.iidI'
Strathmore
UNIVERSITY

• A process may create several new


processes, via a create-process system
call, during the course of execution.

|
Process Creation '&
.,
'tii.iidI'
Strathmor
e
UNIVERSITY

• The creating process is called a


parent process, and the new
processes are called the children of
that process.

|
Process Creation '&
.,
'tii.iidI'
Strathmore
UNIVERSITY

• Each of these new processes may in


turn create other processes, forming a
tree of processes.

|
'& Strathmore
Process Creation .,
'tii.iidI'
UNIVERSITY

• Most operating systems (including


UNIX and the Windows family of
operating systems) identify processes
according to a unique process
identifier (or pid), which is typically
an integer number.

|
Process Creation '&
.,
Strathmore
UNIVERSITY
'tii.iidI'

• In general, a process will need certain


resources (CPU time, memory, files,
I/O devices) to accomplish its task.

|
Process Creation '&
.,
Strathmore
UNIVERSITY
'tii.iidI'

• When a process creates a sub process,


that sub process may be able to
obtain its resources directly from the
operating system, or it may be
constrained to a subset of the
resources of the parent process.

|
Process Creation '&
.,
Strathmore
UNIVERSITY
'tii.iidI'

• The parent may have to partition its


resources among its children, or it
may be able to share some resources
(such as memory or files) among
several of its children.

|
Process Creation '&
.,
'tii.iidI'
Strathmore
UNIVERSITY

• Restricting a child process to a subset


of the parent's resources prevents any
process from overloading the system
by creating too many sub processes.

|
Process Creation '&
.,
'tii.iidI'
Strathmor
e
UNIVERSITY

• Why should a process create sub


processes?

|
Inter -process Communication '&
.,
'tii.iidI'
Strathmore
UNIVERSITY

– Processes may exchange


information, on the same computer
or between computers over a
network

– Communications may be via shared


memory or through message passing

|
III Strathmore
Inter -process Communication .,
~
UNIVERSITY

process
-M process
Two ways of A - r----
A
passing data shared memory
0 1I'
between
process
-M..... process
programs. B -2 ...
.. B
~

2 1

kernel M kernel

Message Passing
- Shared Memory

|
'& Strathmore
., UNIVERSITY

Message passing model


'tii.iidI'

Connection between the processes must be


made
Name of other communicator(computer or
process) must be known (maybe in same
computer or network)
Recipient process must accept
connection.This is done through special
purpose deamons which are system
programs provided for that purpose.

|
'& Strathmor
., e

Message passing model


'tii.iidI'
UNIVERSITY

The source of communication is known as


client and the receiving daemon is known
as server.

|
'& Strathmore
., UNIVERSITY

Shared memory model


'tii.iidI'

Processes use shared memory create and


shared memory to create and gain access
to regions of memory owned by other
processes.
OS tries to prevent one process from
accessing another processes memory.
In this model, processes must remove this
restriction

|
'& Strathmore
., UNIVERSITY

Reading Assignment
'tii.iidI'

Read more on Inter process communication

Page 96 on Silbershatz Book

|
'& Strathmore

Process Termination
., UNIVERSITY
'tii.iidI'

• A process terminates when it finishes


executing its final statement and asks
the operating system to delete it by
using the exit () system call.

|
'& Strathmor

Process Termination
., e
'tii.iidI'
UNIVERSITY

• All the resources of the process—


including physical and virtual memory,
open files, and I/O buffers—are
reallocated by the operating system.

|
'& Strathmore
., UNIVERSITY

Process Termination
'tii.iidI'

• Termination can occur in other


circumstances as well. A process can
cause the termination of another
process via an appropriate system call
(for example, TerminateProcess() in
Win32.

|
'& Strathmore
., UNIVERSITY

Process Termination
'tii.iidI'

• A parent may terminate the execution


of one of its children for a variety of
reasons, such as these

1. The child has exceeded its usage of


some of the resources that it has
been allocated.

|
'& Strathmore
., UNIVERSITY

Process Termination
'tii.iidI'

1. The task assigned to the child is no


longer required.

2. The parent is exiting, and the


operating system does not allow a
child to continue if its parent
terminates.

|
'& Strathmore
Reading Assignment .,
'tii.iidI'
UNIVERSITY

Read and make short notes on Communication in


Client-Server Systems.
1. What is a socket?

2. How do sockets work? Use an example

3. Distinguish between RPC and RMI (One paragraph)

Silberschatz pages 108-115

|
Strathmor
e
UNIVERSITY

Ole Sangale Road, Madaraka Estate. PO Box 59857-00200, Nairobi, Kenya


Tel: (+254) (0)703 034000/200/300 Fax : +254 (0)20 607498
Email: info@strathmore.edu Website: www.strathmore.edu
|