0% found this document useful (0 votes)
3 views87 pages

Process

A process is an executing program that includes the program counter, process stack, and data section. It transitions through various states such as new, running, waiting, ready, and terminated, with state changes managed by system calls. The Process Control Block (PCB) represents the process in the operating system, containing information like process state, program counter, CPU registers, and scheduling information.

Uploaded by

Shreya Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views87 pages

Process

A process is an executing program that includes the program counter, process stack, and data section. It transitions through various states such as new, running, waiting, ready, and terminated, with state changes managed by system calls. The Process Control Block (PCB) represents the process in the operating system, containing information like process state, program counter, CPU registers, and scheduling information.

Uploaded by

Shreya Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 87

Process

What is Process?

● Process is a program in execution.


● Process includes
● Current activity represented by the value of “program counter”
and the contents of processor’s register.
● “Process stack” containing temporary data like subroutine
parameters, return addresses and temporary variables.
● Data section containing global variables.

CC306A:Lecture by Surya Narayan Prasad Slide Number 2


What is Process? …

● “Program is not a process”.


● Program is a passive entity and process is a active entity with a
“program counter” that “specifies the next instruction to be
executed and a set of associated resources”.

CC306A:Lecture by Surya Narayan Prasad Slide Number 3


How is Process created?

● Process can be created using


● Initializationof System
● Running Process p1 is forked p2 … p8
● User / programmer p2 … p8
● Batch Systems : at the time of the starting of the loading of the
executable file say “abc.exe”, the system call “new()” was made.
This is nothing but the result of some batch system.

CC306A:Lecture by Surya Narayan Prasad Slide Number 4


What happens when computer is switched on?

●W

CC306A:Lecture by Surya Narayan Prasad Slide Number 5


States of Process

● As a process executes, it changes its state.


● The state of a process is defined by the current activity of that
process.
● The process states are
● New
● Running
● Waiting
● Ready
● Terminated

CC306A:Lecture by Surya Narayan Prasad Slide Number 6


States of Process: “new”

● The process is being created.

CC306A:Lecture by Surya Narayan Prasad Slide Number 7


States of Process: “running”

● Instructions are being executed.

CC306A:Lecture by Surya Narayan Prasad Slide Number 8


States of Process: “waiting”

● The process is waiting for some event to occur like completion of


I/O or reception of a signal.

CC306A:Lecture by Surya Narayan Prasad Slide Number 9


States of Process: “ready”

● The process is waiting to be assigned to a processor.

CC306A:Lecture by Surya Narayan Prasad Slide Number 10


States of Process: “terminated”

● The process has finished its execution.

CC306A:Lecture by Surya Narayan Prasad Slide Number 11


States of Process: “terminated”

● The process has finished its execution.

CC306A:Lecture by Surya Narayan Prasad Slide Number 12


Changes in States of Process

● Asa process executes, it changes its state. The state of a process is


defined by the current activity of that process. The process states
are
● New i.e. Admit i.e. Loading
● Running i.e. Under execution
● Waiting i.e. Scheduled and Waiting for its Turn
● Ready i.e. Scheduled
● Terminated i.e. Execution is Complete

CC306A:Lecture by Surya Narayan Prasad Slide Number 13


Changes in States of Process …

ready running

new waiting terminated

CC306A:Lecture by Surya Narayan Prasad Slide Number 14


Changes in States of Process …

● The function “new()” is used to create process.


● Oncea process is created, it has to be admitted and for that
purpose, the function “admit()” is used.

CC306A:Lecture by Surya Narayan Prasad Slide Number 15


Changes in States of Process …

● New to Ready: system call admit()


● Ready to Running: Scheduler Dispatch()
● Running to Waiting: system call “wait()” I/O or Event Wait
● Running to Ready: Interrupt handler makes suitable system call
● Waiting to Ready: I/O or Event Completion
● Running to Terminated: system call “exit()”

CC306A:Lecture by Surya Narayan Prasad Slide Number 16


Process Control Block

● Process is represented in the Operating System by a Process


Control Block.
● It is also called as Task Control Block.

CC306A:Lecture by Surya Narayan Prasad Slide Number 17


Process Control Block …
Process State: new, ready ,
CURRENT Process ID
running, waiting ….

Program Counter: NEXT Process Number

Program Number

CPU Register

Memory Limits

List of Open File(s)

CC306A:Lecture by Surya Narayan Prasad Slide Number 18


Process Control Block: Process State

● The state may be


● New
● Ready
● Running
● Waiting
● Terminated

CC306A:Lecture by Surya Narayan Prasad Slide Number 19


Process Control Block: Program Counter

● Thecounter indicates the address of the next instruction to be


executed.

CC306A:Lecture by Surya Narayan Prasad Slide Number 20


Process Control Block: CPU Register

● Registers
is defined as the internal processor memory where data
and instructions are kept temporarily during the execution of the
program.

CC306A:Lecture by Surya Narayan Prasad Slide Number 21


Types of Register

● General Purpose Registers


● Accumulators
● Special Purpose Registers

CC306A:Lecture by Surya Narayan Prasad Slide Number 22


Types of Register: General Purpose Register

● Stores data and intermediate results during the execution of a


program.
● Users can access these registers through instructions.

CC306A:Lecture by Surya Narayan Prasad Slide Number 23


Types of Register: Accumulator

● In accumulator based processor design, the accumulator holds


one of the operands of arithmetic and logical operation.
● Once the execution of arithmetic and logical instruction(s) is / are
done, the result is placed in the accumulator.
● The data transfer between the CPU and device / port are
performed through the accumulator.
● scanf(“%d %d”, &a,&b);
● printf(%d +%d = %d”,a, b, a+b);

CC306A:Lecture by Surya Narayan Prasad Slide Number 24


Types of Register: Special Purpose Register

● These registers are meant for special dedicated purposes


● Program Counter
● Stack Pointer
● Status or Flag Register
● Instruction Register
● Index Register
● Memory Address Register
● Memory Buffer Register or Data Register

CC306A:Lecture by Surya Narayan Prasad Slide Number 25


Types of Register: Special Purpose Register: Program
Counter
● Keeps track of the address of the instruction which is to be
executed next i.e. holds the address of the memory location,
which contains the next instruction to be fetched from the
memory.
● In case of the instructions being executed sequentially, the
contents of Program Counter is incremented automatically after
an execution has been fetched.

CC306A:Lecture by Surya Narayan Prasad Slide Number 26


Types of Register: Special Purpose Register: Program
Counter …
● Incase of jump instructions, the contents of Program Counter are
modified and the program jumps to the memory location which
contains the desired instruction to be executed next.
● The Von Neumann processors contain a program counter.
● The processors based on data flow architecture do not contain
program counter.

CC306A:Lecture by Surya Narayan Prasad Slide Number 27


Types of Register: Special Purpose Register: Stack Pointer

● Holds the address of the last occupied memory location of the


stack i.e. indicates up to what memory locations the stack is
already filled.

CC306A:Lecture by Surya Narayan Prasad Slide Number 28


Types of Register: Special Purpose Register: Status or
Flag Pointer
● Flag is a flip flop which is set or reset by the processor to indicate
certain conditions or set or reset by programmer to control certain
operations.
● The flag that indicate the condition is termed as condition flag.

CC306A:Lecture by Surya Narayan Prasad Slide Number 29


Types of Register: Special Purpose Register: Instruction
Register
● Holds an instruction until it is decoded.
● Ifa processor is having two Instruction Registers, one is used to
fetch the next instruction where as the instruction present at
other is executed.

CC306A:Lecture by Surya Narayan Prasad Slide Number 30


Types of Register: Special Purpose Register: Index
Register
● Used for addressing.
● The address of an operand is sum of the contents of index register
and a constant.
● Instruction involving index register contain constants. This
constant is added to the contents of index register to form the
effective address i.e. the address of the operand.

CC306A:Lecture by Surya Narayan Prasad Slide Number 31


Types of Register: Special Purpose Register: Memory
Address Register
● Holds the address of the instruction or data to be fetched from
memory.
● The CPU transfers the address of the next instruction from the
program counter to the memory address register and from here it
is sent to the memory through the address bus.

CC306A:Lecture by Surya Narayan Prasad Slide Number 32


Types of Register: Special Purpose Register: Memory
Buffer or Data Register
● Connected through data bus.
● Holds the instruction code or data received from or sent to the
memory.
● The data which are written into memory are held in this register
until write operation is completed.

CC306A:Lecture by Surya Narayan Prasad Slide Number 33


CPU Scheduling Information

● CPU scheduling information includes


● Process priority
● Pointers to scheduling queues
● Scheduling Parameters

CC306A:Lecture by Surya Narayan Prasad Slide Number 34


Memory Management Information

● Memory management information includes information like


● Value of Base and Limit Register,
● Page Tables
● Segment Tables

CC306A:Lecture by Surya Narayan Prasad Slide Number 35


Accounting Information

● Accounting Information Includes


● Amount of CPU and Real Time Used,
● Account Number
● Job or Process Number

CC306A:Lecture by Surya Narayan Prasad Slide Number 36


I/O Status Information

● I/O status information includes


● The list of I/O devices allocated to this process
● List of open files

CC306A:Lecture by Surya Narayan Prasad Slide Number 37


Process Scheduling

● The main objective of multiprogramming is to maximize CPU


utilization.
● The main objective of time sharing is to switch the CPU among the
processes so frequently that users can interact with each program
while it is running.

CC306A:Lecture by Surya Narayan Prasad Slide Number 38


Scheduling Queue

● When processes enter the system, they are put in a “Job Queue”.
● The processes that are Ready and Waiting to be executed are kept
in a list termed as “Ready Queue”.
● Each process has its own Process Control Block.
● The Ready Queue Header has a pointer to the first and last Process
Control Blocks in the list.

CC306A:Lecture by Surya Narayan Prasad Slide Number 39


Scheduling Queue …

● Each Process Control Block has a pointer that points to the next
process in the ready queue.
● Device Queue: When a process is allocated the CPU, it executes for
a while and eventually quits, is interrupted or waits for the
occurrence of a particular event like completion of an I/O request
etc. For this an I/O request has been made.

CC306A:Lecture by Surya Narayan Prasad Slide Number 40


Scheduling Queue …

● As there are many processes that have made request to a


particular device and the device may be busy in serving the
request of some process, therefore the process has to wait for its
turn.
● This list of processes waiting for any particular I/O device is called
“Device Queue”.

CC306A:Lecture by Surya Narayan Prasad Slide Number 41


Ready Queue Header & Tailer

Points to first PCB


Head
Tail
Points to last PCB

CC306A:Lecture by Surya Narayan Prasad Slide Number 42


Device Queue Header & Tailer

Points to first requesting process


Head
Tail
Points to last requesting process

CC306A:Lecture by Surya Narayan Prasad Slide Number 43


Queue Representation of Scheduling

admitted Scheduled and Dispatched Terminated


Ready Queue CPU
Non
Device Terminated
I/O (I/O) I/O Request
Queue
Time Slice Expired

Child
Terminates
Child
Executes
Fork a Child

Interrupt Wait for an Interrupt


occurs

CC306A:Lecture by Surya Narayan Prasad Slide Number 44


When a Process comes out of Processor?

● Terminate
● Time quantum expires
● Creation of sub process i.e. child process i.e. Forking
● I/O
● When a high priority job arrives

CC306A:Lecture by Surya Narayan Prasad Slide Number 45


Scheduler

● Process migrates from one scheduling queue to another in its life


time.
● The operating system has to select processes for scheduling
purposes from these queues.
● The selection process is carried out by the SCHEDULER.
● In a batch system, usually more processes are submitted than can
be executed immediately.
● These processes are spooled to a storage device like disk, where
they are kept for later execution.

CC306A:Lecture by Surya Narayan Prasad Slide Number 46


Types of Scheduler

● Long Term i.e. JOB Scheduler


● Short Term i.e. CPU Scheduler
● Medium Term Scheduler

CC306A:Lecture by Surya Narayan Prasad Slide Number 47


Types of Scheduler: Long Term i.e. Job Scheduler

● Selects processes from the pool and loads them into memory for
execution.
● Executes less frequently.
● Controls degree of multiprogramming. If degree of
multiprogramming is stable, then the average rate of process
creation must be equal to the average departure rate of processes
leaving the system.
● May need to be invoked only when a process leaves the system.

CC306A:Lecture by Surya Narayan Prasad Slide Number 48


Types of Scheduler: Short Term i.e. CPU Scheduler

● Selects from among the processes that are ready to execute and
allocate the CPU to one of them.
● Must select new process frequently.
● A process may execute for only a few milliseconds before waiting
for an I/O request.
● Executes frequently can be at interval of say 100 milliseconds.

CC306A:Lecture by Surya Narayan Prasad Slide Number 49


Types of Scheduler: Medium Term Scheduler

● Sometimes it is advantageous to remove processes from memory


and active contention for the CPU to reduce the degree of
multiprogramming.
● Later at some time, the process can be reintroduced into memory
and its execution can be continued from where it was left off.

CC306A:Lecture by Surya Narayan Prasad Slide Number 50


Types of Process

● CPU Bound
● I/O Bound

CC306A:Lecture by Surya Narayan Prasad Slide Number 51


Types of Process: CPU Bound

● The process which in the contention of the CPU.

CC306A:Lecture by Surya Narayan Prasad Slide Number 52


Types of Process: I/O Bound

● The process which in the contention of the I/O Devices.

CC306A:Lecture by Surya Narayan Prasad Slide Number 53


The O/S Components That Help in The Execution of
Program
● “abc.c” is to be executed
● Editor
● Compiler / Interpreter / Assembler
● Loader
● Linker (#include<stdio.h> clrscr())
● Scheduler
● Dispatcher / Traffic Controller
● Processor

CC306A:Lecture by Surya Narayan Prasad Slide Number 54


The O/S Components That Help in The Execution of
Program …
main(): Parent Process: p1 is created by invoking system call “new()”
at the time of beginning of loading. During the loading , the system
call “admit()” is made to complete the task of loading of main()”.
Process p1 will be forked into processes like p2(p21, p22, p23, p24),
p3, p4, p5, p6, p7, p8.

CC306A:Lecture by Surya Narayan Prasad Slide Number 55


The O/S Components That Help in The Execution of
Program …
main()
{
clrscr();
add( printf();, scanf(); c=a+b; printf(););
sub();
mul();

CC306A:Lecture by Surya Narayan Prasad Slide Number 56


The O/S Components That Help in The Execution of
Program …
div();
mod();
getch();
}

CC306A:Lecture by Surya Narayan Prasad Slide Number 57


The O/S Components That Help in The Execution of
Program …
clrscr(): p2 it is child of p1
{
////
}

CC306A:Lecture by Surya Narayan Prasad Slide Number 58


The O/S Components That Help in The Execution of
Program …
add(): p3 it is child of p1
{
////
}

CC306A:Lecture by Surya Narayan Prasad Slide Number 59


The O/S Components That Help in The Execution of
Program …
sub(): p4 it is child of p1
{
////
}

CC306A:Lecture by Surya Narayan Prasad Slide Number 60


The O/S Components That Help in The Execution of
Program …
mul(): p5 it is child of p1
{
////
}

CC306A:Lecture by Surya Narayan Prasad Slide Number 61


The O/S Components That Help in The Execution of
Program …
div(): p6 it is child of p1
{
////
}

CC306A:Lecture by Surya Narayan Prasad Slide Number 62


The O/S Components That Help in The Execution of
Program …
mod(): p7 it is child of p1
{
////
}

CC306A:Lecture by Surya Narayan Prasad Slide Number 63


The O/S Components That Help in The Execution of
Program …
getch(): p8 it is child of p1
{
////
}

CC306A:Lecture by Surya Narayan Prasad Slide Number 64


The O/S Components That Help in The Execution of
Program …
getch(): p8 it is child of p1
{
////
}

CC306A:Lecture by Surya Narayan Prasad Slide Number 65


Kernel

● Kernel is the core or nucleus of the operating system.


● It is the computer program that constitutes the central core of
operating system.
● It has complete control over the system activities.
● Kernel is the first program loaded on the startup and then
manages the remainder of the startup, I/O request.
● The Kernel Code is loaded into a protected area of memory, which
prevents it from being overwritten by others.

CC306A:Lecture by Surya Narayan Prasad Slide Number 66


Kernel …

Applications

Kernel

CPU Memory Device

CC306A:Lecture by Surya Narayan Prasad Slide Number 67


Tasks Performed by Kernel

● Executing Processes
● Handling Interrupts
● To mediate access to the computer resources
● Process Synchronization
● Inter Process Communication

CC306A:Lecture by Surya Narayan Prasad Slide Number 68


System Call

● When a process makes requests of the Kernel, the request is


termed as “System Call”.
● System call is how a program requests a service from an operating
system’s kernel.
● System calls provide the interface between a process and the
operating system.
● A system call is the mechanism that is used by the application
program to request a service from the operating system.

CC306A:Lecture by Surya Narayan Prasad Slide Number 69


System Call …

● Machinecode instruction is used, that causes the processor to


change mode.

CC306A:Lecture by Surya Narayan Prasad Slide Number 70


How to Call Kernel Functions?

● Using Interrupt
● Using “call gate”
● Call Gate is a special address stored by the kernel in a list in
kernel memory at a location known to the processor.
● When the processor detects a call to that address, it redirects
to the target location without causing an access violation.
● Using Special System Call Instruction

CC306A:Lecture by Surya Narayan Prasad Slide Number 71


Shell

● User interface for access to an operating system services.


● Operating System Shell uses either Command Line Interface (CLI)
or Graphical user Interface (GUI).
● Design of a shell is guided by
● Cognitive Ergonomics ( applied science concerned with
designing and arranging things people use so that the people
and things interact most efficiently and safely)
● Mental Processes like perception, memory, reasoning and
motor response.

CC306A:Lecture by Surya Narayan Prasad Slide Number 72


Shell …

● Mental Workload, Decision Making, Skilled performance,


Human Computer Interaction, Human Reliability, Work Stress
and training
● Studies cognition in work and operational settings, in order to
optimize human well being and system performance.
● Goal is to achieve the best workflow possible for the intended
tasks.

CC306A:Lecture by Surya Narayan Prasad Slide Number 73


Thread

●A thread is a flow of execution through the process code, with its


own program counter that keeps track of which instruction to
execute next, system registers which hold its current working
variables, and a stack which contains the execution history.
● A thread shares with its peer threads few information like code
segment, data segment and open files. When one thread alters a
code segment memory item, all other threads see that.

CC306A:Lecture by Surya Narayan Prasad Slide Number 74


Thread …

● A thread is also called a lightweight process.


● Threads provide a way to improve application performance
through parallelism.
● Threads represent a software approach to improving performance
of operating system by reducing the overhead thread is equivalent
to a classical process.
● Each thread belongs to exactly one process and no thread can
exist outside a process.

CC306A:Lecture by Surya Narayan Prasad Slide Number 75


Thread …

● Each thread represents a separate flow of control.


● Threads have been successfully used in implementing network
servers and web server.
● Thread provide a suitable foundation for parallel execution of
applications on shared memory multiprocessors.
● The following figure shows the working of a single-threaded and a
multithreaded process.
● The following figure shows the working of a single-threaded and a
multithreaded process.

CC306A:Lecture by Surya Narayan Prasad Slide Number 76


Thread …

Register Counter Stack Register Register Register

Counter Counter Counter

Stack Stack Stack


Data Files

Data Files
Code

Code

Thread Thread Thread Thread

CC306A:Lecture by Surya Narayan Prasad Slide Number 77


Difference Between Process and Thread

Process Thread
● Process is heavy weight or ● Thread is light weight, taking
resource intensive. lesser resources than a
process.
● Process switching needs ● Thread switching does not
interaction with operating need to interact with
system. operating system.

CC306A:Lecture by Surya Narayan Prasad Slide Number 78


Difference Between Process and Thread …
Process Thread
● In multiple processing ● All threads can share same set
environments, each process of open files, child processes.
executes the same code but
has its own memory and file
resources.
● If one process is blocked, then ● While one thread is blocked
no other process can execute and waiting, a second thread
until the first process is in the same task can run.
unblocked.
CC306A:Lecture by Surya Narayan Prasad Slide Number 79
Difference Between Process and Thread …

Process Thread
● Multiple processes without ● Multiple threaded processes
using threads use more use fewer resources.
resources.
● In multiple processes each ● One thread can read, write or
process operates change another thread's data.
independently of the others.

CC306A:Lecture by Surya Narayan Prasad Slide Number 80


Advantages of Thread

● Threads minimize the context switching time.


● Use of threads provides concurrency within a process.
● Efficient communication.
● It is more economical to create and context switch threads.
● Threads allow utilization of multiprocessor architectures to a
greater scale and efficiency.

CC306A:Lecture by Surya Narayan Prasad Slide Number 81


Types of Thread

● User Level Threads


● Kernel Level Threads

CC306A:Lecture by Surya Narayan Prasad Slide Number 82


Types of Thread: User Level Thread

● The thread management kernel is not aware of the existence of


threads.
● The thread library contains code for creating and destroying
threads, for passing message and data between threads, for
scheduling thread execution and for saving and restoring thread
contexts.
● The application starts with a single thread.

CC306A:Lecture by Surya Narayan Prasad Slide Number 83


Types of Thread: Kernel Level Thread

● Thread management is done by the Kernel.


● There is no thread management code in the application area.
● Kernel threads are supported directly by the operating system.
● Any application can be programmed to be multithreaded.
● Allof the threads within an application are supported within a
single process.

CC306A:Lecture by Surya Narayan Prasad Slide Number 84


Types of Thread: Kernel Level Thread …

● The Kernel maintains context information for the process as a


whole and for individuals threads within the process.
● Scheduling by the Kernel is done on a thread basis.
● The Kernel performs thread creation, scheduling and management
in Kernel space.
● Kernel threads are generally slower to create and manage than the
user threads.

CC306A:Lecture by Surya Narayan Prasad Slide Number 85


Difference Between User Level and Kernel Level Thread

User Level Thread Kernel Level Thread


● User-level threads are faster to ● Kernel-level threads are slower
create and manage. to create and manage.
● Implementation is by a thread ● Operating system supports
library at the user level. creation of Kernel threads.
● User-level thread is generic ● Kernel-level thread is specific
and can run on any operating to the operating system.
system.

CC306A:Lecture by Surya Narayan Prasad Slide Number 86


Difference Between User Level and Kernel Level Thread

User Level Thread Kernel Level Thread


● Multi-threaded applications ● Kernel routines themselves
cannot take advantage of can be multithreaded.
multiprocessing.

CC306A:Lecture by Surya Narayan Prasad Slide Number 87

You might also like