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

Process LIfecycle and PCB

Uploaded by

Umer Naveed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Process LIfecycle and PCB

Uploaded by

Umer Naveed
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Operating Systems

By
Hamna Khalid

Department of Software Engineering


University of Sahiwal

1
Process Concept & Scheduling
and
Process Control Block(PCB)

2
Process
• A process is an instance of a program in
execution.
• Batch systems work in terms of "jobs". Many
modern process concepts are still expressed in
terms of jobs, ( e.g. job scheduling ), and the
two terms are often used interchangeably.

3
Process
• A process is a program in execution which then
forms the basis of all computation.
• The process is not as same as program code but
a lot more than it.
• A process is an 'active' entity as opposed to the
program which is considered to be a 'passive'
entity.
• Attributes held by the process include
hardware state, memory, CPU, etc.
4
Process in Memory
Process memory is divided into four sections for efficient
working :
• The Text section is made up of the compiled program code,
read in from non-volatile storage when the program is
launched.
• The Data section is made up of the global and static variables,
allocated and initialized prior to executing the main.
• The Heap is used for the dynamic memory allocation and is
managed via calls to new, delete, free, etc.
• The Stack is used for local variables. Space on the stack is
reserved for local variables when they are declared.

5
Process in Memory

6
Process Scheduling
• When there are two or more runnable
processes then it is decided by the Operating
system which one to run first then it is
referred to as Process Scheduling.
• A scheduler is used to make decisions by using
some scheduling algorithm.

7
3 Types of Scheduling Queues
• Job queue − This queue keeps all the
processes in the system.
• Ready queue − This queue keeps a set of all
processes residing in main memory, ready and
waiting to execute. ...
• Device queues − The processes which are
blocked due to unavailability of an I/O device
constitute this queue.

8
Process States

9
Process Lifecycle

10
Categories of Process Scheduling
Scheduling falls into one of two categories:

• Non-preemptive: In this case, a process’s resource cannot be


taken before the process has finished running. When a
running process finishes and transitions to a waiting state,
resources are switched.
• Preemptive: In this case, the OS assigns resources to a
process for a predetermined period. The process switches
from running state to ready state or from waiting for state to
ready state during resource allocation. This switching happens
because the CPU may give other processes priority and
substitute the currently active process for the higher priority
process.

11
Job Scheduling vs. CPU Scheduling

• The job scheduling is the mechanism to select


which process has to be brought into the
ready queue.
• The CPU scheduling is the mechanism to
select which process has to be executed next
and allocates the CPU to that process.

12
Types of Process Schedulers

There are three types of process schedulers:


1. Long-Term or Job Scheduler:
It brings the new process to the ‘Ready State’. It controls the
Degree of Multi-programming, i.e., the number of processes
present in a ready state at any point in time. The long-term
scheduler must make a careful selection of both I/O and CPU-
bound processes. I/O-bound tasks are which use much of their
time in input and output operations while CPU-bound processes
are which spend their time on the CPU. The job scheduler
increases efficiency by maintaining a balance between the two.
They operate at a high level and are typically used in batch-
processing systems.

13
Types of Process Schedulers

2. Short-term or CPU Scheduler


It is responsible for selecting one process from the ready state
for scheduling it on the running state. Note: Short-term
scheduler only selects the process to schedule it doesn’t load the
process on running. Here is when all the scheduling algorithms
are used. The CPU scheduler is responsible for ensuring no
starvation due to high burst time processes.

14
Types of 3. Medium-Term Scheduler
It is responsible for suspending and resuming the process. It
Process mainly does swapping (moving processes from main memory
Schedulers to disk and vice versa). Swapping may be necessary to
improve the process mix or because a change in memory
requirements has overcommitted available memory,
requiring memory to be freed up. It is helpful in maintaining a
perfect balance between the I/O bound and the CPU bound.

15
Process Control Block
• There is a Process Control Block for each
process, enclosing all the information about
the process. It is also known as the task
control block.

16
Process Control Block

17
Process Control Block
It is a data structure, which contains the following:
• Process State: It can be running, waiting, etc.
• Process ID and the parent process ID.
• CPU registers and Program Counter. Program
Counter holds the address of the next
instruction to be executed for that process.
• CPU Scheduling information: Such as priority
information and pointers to scheduling queues.

18
Process Control Block
• Memory Management information: For
example, page tables or segment tables.
• Accounting information: The User and kernel
CPU time consumed, account numbers, limits,
etc.
• I/O Status information: Devices allocated,
open file tables, etc.

19
Process vs. Program
Process Program
A Program is basically a
The process is basically collection of
an instance of the instructions that mainly
computer program that performs a specific task
is being executed. when executed by the
computer.

20
Process vs. Program
A process has A Program has
a shorter lifetime. a longer lifetime.
A Process requires A Program is stored
resources such as by hard-disk and
memory, CPU, Input- does not require any
Output devices. resources.

21
Process vs. Program
A process has a
A Program has static
dynamic instance of
code and static data.
code and data
Basically, a process is On the other hand, the
the running instance of program is
the code. the executable code.

22

You might also like