0% found this document useful (0 votes)
4 views

Process Concept

The document discusses the concept of processes in operating systems, detailing their execution, memory layout, and state transitions. It explains the structure and function of the Process Control Block (PCB), which contains essential information for managing processes, and describes the role of schedulers in process management. Additionally, it covers context switching and the different types of scheduling, including long-term, short-term, and medium-term scheduling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Process Concept

The document discusses the concept of processes in operating systems, detailing their execution, memory layout, and state transitions. It explains the structure and function of the Process Control Block (PCB), which contains essential information for managing processes, and describes the role of schedulers in process management. Additionally, it covers context switching and the different types of scheduling, including long-term, short-term, and medium-term scheduling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Lecture 2b

OPERATING SYSTEMS

Operating System Concepts – 9 th Edition 1.1 Silberschatz, Galvin and Gagne ©2013
Process Concept
 An operating system executes a variety of programs:
 Batch system – jobs
 Time-shared systems – user programs or tasks
 Textbook uses the terms job and process almost
interchangeably
 Process – a program in execution; process execution must
progress in sequential fashion
 A process includes:
 program counter
 stack
 data section
Process in Memory

When a program is loaded into the


memory and it becomes a process, it
can be divided into four sections ─
stack, heap, data and text. The
following image shows a simplified
layout of a process inside main
memory

Address space growth


Text: doesn’t grow
Data: grows “up”
Stack: grows “down”
Process in Memory
S.N. Component & Description

1 Stack
Stack contains the temporary data such as method/function parameters, return
address and local variables or procedure call information.

2 Heap
This is dynamically allocated memory to a process during its run time.

3 Data
This section contains the global and static variables. “program data” Statically
declared variables, Areas allocated by malloc() or new

4 Text
This includes the current activity represented by the value of Program Counter and
the contents of the processor's registers. “program code”
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
 ready:The process is waiting to be assigned to a processor
 terminated: The process has finished execution
Process Control Block (PCB)
A Process Control Block (PCB, also called Task Controlling Block or
Task Struct) is a data structure in the OS kernel containing the
information needed to manage a particular process.
The PCB is "the manifestation of a process in an operating system"

Information associated with each process


 Process state
 Program counter
 CPU registers
 CPU scheduling information
 Memory-management information
 Accounting information
 I/O status information
Process Control Block (PCB)

 Process state – running, waiting, etc.


 Program counter – location of instruction to next
execute
 CPU registers – contents of all process-centric
registers
 CPU scheduling information- priorities, scheduling
queue pointers
 Memory-management information – memory
allocated to the process
 Accounting information – CPU used, clock time
elapsed since start, time limits
 I/O status information – I/O devices allocated to
process, list of open files
PCB info (another view)
CPU Switch From Process to Process
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 via a context switch

Context of a process represented in the PCB

Context-switch time is pure overhead; the system does no


useful work while switching
The more complex the OS and the PCB  the longer the
context switch

Time dependent on hardware support


Some hardware provides multiple sets of registers per CPU 
multiple contexts loaded at once
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
How process state changes-1

Ready Ready Ready

€ a := 1 € a := 1 € a := 1
b := a + 1 read a file b := a + 1
c := b + 1 b := a + 1 c := b + 1
read a file c := b + 1 a := b - c
a := b - c a := b - c c := c * b
c := c * b c := c * b b := 0
b := 0 b := 0 c := 0
How process state changes-2

Running Ready Ready

€ a := 1 € a := 1 € a := 1
a
b := :=a 1+ 1 read a file b := a + 1
€ c :=b:=
a :=
b+
1a +
1 b := a1 +1 b := a + 1 c := b + 1
read ca:= fileb + c := b + 1 a := b - c
c€
:= b + 1
1aread
:=
readb - ac file a := b - c c := c * b
c := c:=*abbfile Timeout
c := c * b b := 0
a
:=0 b - c- c
b a:= b := 0 c := 0
c c:=:=c c* *b b
b b:=:=0 0
How process state changes-3

Ready Running Ready

a := 1 € a := 1 € a := 1
b := a + 1 a
read :=a1file b := a + 1
c := b+1 € b :=read
a+a 1 fie
l c := b + 1
read a ffi
le cb:=:=ba++1 1 a := b - c
a := b - c ac:=:=bb-+ c1 c := c * b
c := c * b a :=
c := c *bb- c b := 0
b := 0 b c:=:=0 c * b c := 0
b := 0

I/O
How process state changes-4

Ready Blocked Running

a := 1 a := 1 € a := 1
b := a + 1 € read a fie
l a
b :=:=a1+ 1
€ c := ab:=:=+ 1a +
c := b + 1 b := a + 1
1 b := a 1
b +1
€ read a file c := b + 1 a := b c 1-:=cb+
a := b - c c := a := b - c c€:=
c :=b +
c*b
a 1:=
c * b b := Timeout
c := c * b := b0 b
ab :=
-c
0 b := 0 c c:= :=0 c * bc :=
- c
b c:=* 0b b :=
c := 00
c := 0
Representation of Process Scheduling
 Scheduling refers to the way processes are assigned to
run on the available CPUs, since there are typically
many more processes running than there are available
CPUs.
 This assignment is carried out by software known as a
scheduler or dispatcher.
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

 Some systems have no LTS.


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
Addition of Medium Term Scheduling

The process is swapped out, and is later swapped in, by the


medium-term scheduler
Swapping may be done to free memory.

You might also like