You are on page 1of 21

Introduction to Operating Systems

Processes

By:
Syed Waqas Haider
Department of Computer Sciences,
COMSATS Institute of Information Technology,The Mall
Wah Cantt, Pakistan
Introduction to Processes
• Concept of a process is fundamental to an operating
system
• Can be viewed as an abstraction of a program
– Although to be strict we can say that a program (i.e. an algorithm
expressed in some suitable notation) has a process that
executes the algorithm and has associated with it input, output
and a state.
• Computers nowadays can do many things at the same
time. They can be writing to a printer, reading from a disc
and scanning an image
Introduction to Processes (Contd..)
• The computer (more strictly the operating system) is also
responsible for running many processes, usually, on the
same CPU
• Must give the illusion that the computer is doing many
things at the same time (pseudoparallelism)
• Important to realise
– The CPU is switching processes
– One process can have an effect on another process which is not
currently running.
Process in Memory

A process includes:
program counter
stack
data section
Process State
• 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 (A waiting process is unable
to run until some external event has taken place. For example, it may be waiting for data to be
retrieved from a disc.)
– ready: The process is waiting to be assigned to a process ( A process that is ready is
runnable but cannot get access to the CPU due to another process using it. )
– terminated: The process has finished execution

The scheduler is concerned with


deciding which one of the processes in a
ready state should be allowed to move to
a running state Running. Only one
process can be running at any one time
(assuming a single processor machine).
A running process is the process that is
actually using the CPU at that time.
Process State
Process Control Blocks - 1

• When a process moves from a running state to a ready


or blocked state it must store certain information so that
it can restart from the same point when it moves back to
a running state
– Which instruction it was about to execute
– Which record it was about to read from its input file
– Values in the registers
Process Control Blocks - 2
• Each process has a process table
Process Management
 Registers
      

 Program Counter
      

 Program Status Word


      

 Stack Pointer
      

 Process State
      

 Time when process started


      

 CPU time used


      

 Time of next alarm


      

 Process id
      

• Note that accounting information is stored as well


CPU Switch From Process to Process
Process Scheduling Queues

• Job queue – set of all processes in the system


• Ready queue – set of all processes residing in main memory,
ready and waiting to execute
• Device queues – set of processes waiting for an I/O device
• Processes migrate among the various queues
Ready Queue And Various I/O Device Queues
Representation of Process Scheduling
Schedulers
• Long-term scheduler (or job scheduler) – selects which
processes should be brought into the ready queue
• Short-term scheduler (or CPU scheduler) – selects which
process should be executed next and allocates CPU
Addition of Medium Term Scheduling
Schedulers (Cont.)
• 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
• Processes can be described as either:
– I/O-bound process – spends more time doing I/O than
computations, many short CPU bursts
– CPU-bound process – spends more time doing computations;
few very long CPU bursts
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
• Context-switch time is overhead; the system does no useful work
while switching
• Time dependent on hardware support
Interrupt

• A signal informing a program that an event has occurred.


When a program receives an interrupt signal, it takes a
specified action (which can be to ignore the signal).
Interrupt signals can cause a program to suspend itself
temporarily to service the interrupt.
• Interrupt signals can come from a variety of sources. For
example, every keystroke generates an interrupt signal.
Interrupts can also be generated by other devices, such
as a printer, to indicate that some event has occurred.
These are called hardware interrupts. Interrupt signals
initiated by programs are called software interrupts. A
software interrupt is also called a trap or an exception.
• PCs support 256 types of software interrupts
and 15 hardware interrupts. Each type of
software interrupt is associated with an interrupt
handler -- a routine that takes control when the
interrupt occurs. For example, when you press a
key on your keyboard, this triggers a specific
interrupt handler. The complete list of interrupts
and associated interrupt handlers is stored in a
table called the interrupt vector table, which
resides in the first 1 K of addressable memory.
Interrupt Vector Table

• A table of interrupt vectors (pointers to routines


that handle interrupts). On PCs, the interrupt
vector table consists of 256 4-byte pointers, and
resides in the first 1 K of addressable memory.
Each interrupt number is reserved for a specific
purpose. For example, 16 of the vectors are
reserved for the 16 IRQ lines.
• An interrupt vector table is also called a dispatch
table.
Types of Interrupt

• Program
Generated by some condition that occurs as a
result of an instruction execution ,such as
arithmetic overflow ,division by zero ,attempt to
execute an illegal machine instruction.
• Timer
Generated by a timer within the processor. This
allows the os to perform certain function on a
regular basis.
Types of Interrupt

• I/O
Generated by I/O controller, to signal normal
completion of an operation or to signal a variety
of error conditions.
• Hardware failure
Generated by a failure ,such as power or memory
parity error.

You might also like