Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Short Notes for Computer Science Engineering  >  Short Notes: Processes Managements - Process and Threads

Short Notes: Processes Managements - Process and Threads | Short Notes for Computer Science Engineering - Computer Science Engineering (CSE) PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


Process: A process can be defined in any of the following ways
• A process is a program in execution.
• It is an asynchronous activity.
• It is the entity to which processors are assigned.
• It is the dispatchable unit.
• It is the unit of work in a system.
A process is more than the program code. It also includes the current activity as 
represented by following:
• Current value of Program Counter (PC)
• Contents of the processors registers
• Value of the variables
• The process stack which contains temporary data such as subroutine 
parameter, return address, and temporary variables.
• A data section that contains global variables.
Process in Memory: Each process is represented in the as by a Process Control 
Block (PCB) also called a task control block.
PCB: A process in an operating system is represented by a data structure known as 
a process control block (PCB) or process descriptor.
Page 2


Process: A process can be defined in any of the following ways
• A process is a program in execution.
• It is an asynchronous activity.
• It is the entity to which processors are assigned.
• It is the dispatchable unit.
• It is the unit of work in a system.
A process is more than the program code. It also includes the current activity as 
represented by following:
• Current value of Program Counter (PC)
• Contents of the processors registers
• Value of the variables
• The process stack which contains temporary data such as subroutine 
parameter, return address, and temporary variables.
• A data section that contains global variables.
Process in Memory: Each process is represented in the as by a Process Control 
Block (PCB) also called a task control block.
PCB: A process in an operating system is represented by a data structure known as 
a process control block (PCB) or process descriptor.
Max
Slack
i
t
Heap
Data
Text
— » Contains temporary data (such as function parameters, return 
addresses and local variables)
— > Memory that is dynamically allocated during process run lime. 
— » Data section contains global variables 
— * Code section
A simple process block
The PCB contains important information about the specific process including
• The current state of the process i.e., whether it is ready, running, waiting, or 
whatever.
• Unique identification of the process in order to track "which is which" 
information.
• A pointer to parent process.
• Similarly, a pointer to child process (if it exists).
• The priority of process (a part of CPU scheduling information).
• Pointers to locate memory of processes.
• A register save area.
• The processor it is running on.
Process State Model
I/O or event 
completion
Waiting 
Diagram of a process state
I/O or event 
wait
Process state: The process state consist of everything necessary to resume the 
process execution if it is somehow put aside temporarily. The process state 
consists of at least following:
• Code for the program.
• Program's static data.
• Program's dynamic data.
• Program's procedure call stack.
• Contents of general purpose registers.
• Contents of program counter (PC)
• Contents of program status word (PSW).
• Operating Systems resource in use.
A process goes through a series of discrete process states.
• New State: The process being created.
• Running State: A process is said to be running if it has the CPU, that is, 
process actually using the CPU at that particular instant.
Page 3


Process: A process can be defined in any of the following ways
• A process is a program in execution.
• It is an asynchronous activity.
• It is the entity to which processors are assigned.
• It is the dispatchable unit.
• It is the unit of work in a system.
A process is more than the program code. It also includes the current activity as 
represented by following:
• Current value of Program Counter (PC)
• Contents of the processors registers
• Value of the variables
• The process stack which contains temporary data such as subroutine 
parameter, return address, and temporary variables.
• A data section that contains global variables.
Process in Memory: Each process is represented in the as by a Process Control 
Block (PCB) also called a task control block.
PCB: A process in an operating system is represented by a data structure known as 
a process control block (PCB) or process descriptor.
Max
Slack
i
t
Heap
Data
Text
— » Contains temporary data (such as function parameters, return 
addresses and local variables)
— > Memory that is dynamically allocated during process run lime. 
— » Data section contains global variables 
— * Code section
A simple process block
The PCB contains important information about the specific process including
• The current state of the process i.e., whether it is ready, running, waiting, or 
whatever.
• Unique identification of the process in order to track "which is which" 
information.
• A pointer to parent process.
• Similarly, a pointer to child process (if it exists).
• The priority of process (a part of CPU scheduling information).
• Pointers to locate memory of processes.
• A register save area.
• The processor it is running on.
Process State Model
I/O or event 
completion
Waiting 
Diagram of a process state
I/O or event 
wait
Process state: The process state consist of everything necessary to resume the 
process execution if it is somehow put aside temporarily. The process state 
consists of at least following:
• Code for the program.
• Program's static data.
• Program's dynamic data.
• Program's procedure call stack.
• Contents of general purpose registers.
• Contents of program counter (PC)
• Contents of program status word (PSW).
• Operating Systems resource in use.
A process goes through a series of discrete process states.
• New State: The process being created.
• Running State: A process is said to be running if it has the CPU, that is, 
process actually using the CPU at that particular instant.
• Blocked (or waiting) State: A process is said to be blocked if it is waiting for 
some event to happen such that as an I/O completion before it can proceed. 
Note that a process is unable to run until some external event happens.
• Ready State: A process is said to be ready if it use a CPU if one were 
available. A ready state process is runable but temporarily stopped running to 
let another process run.
• Terminated state: The process has finished execution.
Schedulers: A process migrates among various scheduling queues throughout its 
lifetime. The OS must select for scheduling purposes, processes from those 
queues in some fashion. The selection process is carried out by the appropriate 
scheduler.
Long Term Scheduler: A long term scheduler or job scheduler selects processes 
from job pool (mass storage device, where processes are kept for later execution) 
and loads them into memory for execution. The long term scheduler controls the 
degree of multiprogramming (the number of processes in memory).
Short Term Scheduler: A short term scheduler or CPU scheduler selects from the 
main memory among the processes that are ready to execute and allocates the 
CPU to one of them.Medium Term Scheduler: The medium term scheduler available 
in all systems which is responsible for the swapping in and out operations which 
means loading the process into, main memory from secondary memory (swap in) 
and take out the process from main memory and store it into the secondary 
memory (swap out).
A sp ects :
L on g Term 
S ch ed u ler
M ed iu m Term 
S ch ed u ler
S h ort Term 
S ch ed u ler
C alled as
It is a j o b s c h e d u le r It is a p ro c e s s 
s w a p p in g
It is a C P U s c h e d u le r
Speed
S p e e d is le s s e r th a n S p e e d is in b e tw e e n S p e e d is fa s te st a m o n g 
sh o rt te rm b o th tw o o th e r s c h e d u le r 
s c h e d u le r s h o rt an d lo n g te rm 
s c h e d u le r
M u lti prog rani ruing
It c o n tro ls th e It re d u c e s th e d e g re e It p ro v id e s le s s e r 
d e g re e o f o f c o n tr o l o v e r d e g re e o f 
m u ltip ro g ra m m in g m u ltip r o g r a m m in g m u ltip ro g ra m m in g
T im e-sh arin g sy stem
It is a lm o s t a b s e n t It is a p a rt o f T im e It is a ls o m in im a l in 
o r m in im a l in tim e s h a r in g s y s te m tim e s h a rin g sy s te m 
s h a rin g sy s te m
P rocesses
It s e le c ts p ro c e s s e s It c a n r e in tro d u c e 
fro m p o o l a n d th e p ro c e s s in to 
lo a d s th e m in to m e m o ry an d 
m e m o ry fo r e x e c u tio n c a n b e 
e x e c u tio n c o n tin u e d
It se le c ts th o s e 
p ro c e s s e s w h ic h are 
r e a d y to e x e c u te
Dispatcher:
• It is the module that gives control of the CPU to the process selected by the 
short-term scheduler.
• Functions of Dispatcher: Switching context, Switching to user mode, and 
Jumping to the proper location in the user program to restart that program.
Page 4


Process: A process can be defined in any of the following ways
• A process is a program in execution.
• It is an asynchronous activity.
• It is the entity to which processors are assigned.
• It is the dispatchable unit.
• It is the unit of work in a system.
A process is more than the program code. It also includes the current activity as 
represented by following:
• Current value of Program Counter (PC)
• Contents of the processors registers
• Value of the variables
• The process stack which contains temporary data such as subroutine 
parameter, return address, and temporary variables.
• A data section that contains global variables.
Process in Memory: Each process is represented in the as by a Process Control 
Block (PCB) also called a task control block.
PCB: A process in an operating system is represented by a data structure known as 
a process control block (PCB) or process descriptor.
Max
Slack
i
t
Heap
Data
Text
— » Contains temporary data (such as function parameters, return 
addresses and local variables)
— > Memory that is dynamically allocated during process run lime. 
— » Data section contains global variables 
— * Code section
A simple process block
The PCB contains important information about the specific process including
• The current state of the process i.e., whether it is ready, running, waiting, or 
whatever.
• Unique identification of the process in order to track "which is which" 
information.
• A pointer to parent process.
• Similarly, a pointer to child process (if it exists).
• The priority of process (a part of CPU scheduling information).
• Pointers to locate memory of processes.
• A register save area.
• The processor it is running on.
Process State Model
I/O or event 
completion
Waiting 
Diagram of a process state
I/O or event 
wait
Process state: The process state consist of everything necessary to resume the 
process execution if it is somehow put aside temporarily. The process state 
consists of at least following:
• Code for the program.
• Program's static data.
• Program's dynamic data.
• Program's procedure call stack.
• Contents of general purpose registers.
• Contents of program counter (PC)
• Contents of program status word (PSW).
• Operating Systems resource in use.
A process goes through a series of discrete process states.
• New State: The process being created.
• Running State: A process is said to be running if it has the CPU, that is, 
process actually using the CPU at that particular instant.
• Blocked (or waiting) State: A process is said to be blocked if it is waiting for 
some event to happen such that as an I/O completion before it can proceed. 
Note that a process is unable to run until some external event happens.
• Ready State: A process is said to be ready if it use a CPU if one were 
available. A ready state process is runable but temporarily stopped running to 
let another process run.
• Terminated state: The process has finished execution.
Schedulers: A process migrates among various scheduling queues throughout its 
lifetime. The OS must select for scheduling purposes, processes from those 
queues in some fashion. The selection process is carried out by the appropriate 
scheduler.
Long Term Scheduler: A long term scheduler or job scheduler selects processes 
from job pool (mass storage device, where processes are kept for later execution) 
and loads them into memory for execution. The long term scheduler controls the 
degree of multiprogramming (the number of processes in memory).
Short Term Scheduler: A short term scheduler or CPU scheduler selects from the 
main memory among the processes that are ready to execute and allocates the 
CPU to one of them.Medium Term Scheduler: The medium term scheduler available 
in all systems which is responsible for the swapping in and out operations which 
means loading the process into, main memory from secondary memory (swap in) 
and take out the process from main memory and store it into the secondary 
memory (swap out).
A sp ects :
L on g Term 
S ch ed u ler
M ed iu m Term 
S ch ed u ler
S h ort Term 
S ch ed u ler
C alled as
It is a j o b s c h e d u le r It is a p ro c e s s 
s w a p p in g
It is a C P U s c h e d u le r
Speed
S p e e d is le s s e r th a n S p e e d is in b e tw e e n S p e e d is fa s te st a m o n g 
sh o rt te rm b o th tw o o th e r s c h e d u le r 
s c h e d u le r s h o rt an d lo n g te rm 
s c h e d u le r
M u lti prog rani ruing
It c o n tro ls th e It re d u c e s th e d e g re e It p ro v id e s le s s e r 
d e g re e o f o f c o n tr o l o v e r d e g re e o f 
m u ltip ro g ra m m in g m u ltip r o g r a m m in g m u ltip ro g ra m m in g
T im e-sh arin g sy stem
It is a lm o s t a b s e n t It is a p a rt o f T im e It is a ls o m in im a l in 
o r m in im a l in tim e s h a r in g s y s te m tim e s h a rin g sy s te m 
s h a rin g sy s te m
P rocesses
It s e le c ts p ro c e s s e s It c a n r e in tro d u c e 
fro m p o o l a n d th e p ro c e s s in to 
lo a d s th e m in to m e m o ry an d 
m e m o ry fo r e x e c u tio n c a n b e 
e x e c u tio n c o n tin u e d
It se le c ts th o s e 
p ro c e s s e s w h ic h are 
r e a d y to e x e c u te
Dispatcher:
• It is the module that gives control of the CPU to the process selected by the 
short-term scheduler.
• Functions of Dispatcher: Switching context, Switching to user mode, and 
Jumping to the proper location in the user program to restart that program.
The fork():
System call fork() is used to create processes. It takes no arguments and returns a 
process ID . The purpose of fork() is to create a new process, which becomes 
the child process of the caller. After a new child process is created, both processes 
will execute the next instruction following the forkQ system call. Therefore, we 
have to distinguish the parent from the child. This can be done by testing the 
returned value of fork():
• If fork() returns a negative value, the creation of a child process was 
unsuccessful.
• fork() returns a zero to the newly created child process.
• fork() returns a positive value, the process ID of the child process, to the 
parent. The returned process ID is of type pid_t defined in sys/types.h. 
Normally, the process ID is an integer. Moreover, a process can use 
function getpid() to retrieve the process ID assigned to this process.
Therefore, after the system call to fork(), a simple test can tell which process is the 
child. Please note that Unix will make an exact copy of the parent's address space 
and give it to the child. Therefore, the parent and child processes 
have separate address spaces.
Example:
Calculate a number of times hello is printed.
#include <stdio.h>
#include <sys/types.h> 
int main()
{
forkQ;
forkQ;
forkQ;
printf("hello\n"); 
return 0;
}
Solutions:
Number of times hello printed is equal to number of processes created. Total 
Number of Processes = 2n where n is the number of fork system calls. So here n =
3, 23 = 8.
Ques: what are threads?
Thread: A thread is a single sequence stream within in a process. Because threads 
have some of the properties of processes, they are sometimes called lightweight 
processes. In a process, threads allow multiple executions of streams. An 
operating system that has thread facility, the basic unit of CPU utilization is a 
thread.
Page 5


Process: A process can be defined in any of the following ways
• A process is a program in execution.
• It is an asynchronous activity.
• It is the entity to which processors are assigned.
• It is the dispatchable unit.
• It is the unit of work in a system.
A process is more than the program code. It also includes the current activity as 
represented by following:
• Current value of Program Counter (PC)
• Contents of the processors registers
• Value of the variables
• The process stack which contains temporary data such as subroutine 
parameter, return address, and temporary variables.
• A data section that contains global variables.
Process in Memory: Each process is represented in the as by a Process Control 
Block (PCB) also called a task control block.
PCB: A process in an operating system is represented by a data structure known as 
a process control block (PCB) or process descriptor.
Max
Slack
i
t
Heap
Data
Text
— » Contains temporary data (such as function parameters, return 
addresses and local variables)
— > Memory that is dynamically allocated during process run lime. 
— » Data section contains global variables 
— * Code section
A simple process block
The PCB contains important information about the specific process including
• The current state of the process i.e., whether it is ready, running, waiting, or 
whatever.
• Unique identification of the process in order to track "which is which" 
information.
• A pointer to parent process.
• Similarly, a pointer to child process (if it exists).
• The priority of process (a part of CPU scheduling information).
• Pointers to locate memory of processes.
• A register save area.
• The processor it is running on.
Process State Model
I/O or event 
completion
Waiting 
Diagram of a process state
I/O or event 
wait
Process state: The process state consist of everything necessary to resume the 
process execution if it is somehow put aside temporarily. The process state 
consists of at least following:
• Code for the program.
• Program's static data.
• Program's dynamic data.
• Program's procedure call stack.
• Contents of general purpose registers.
• Contents of program counter (PC)
• Contents of program status word (PSW).
• Operating Systems resource in use.
A process goes through a series of discrete process states.
• New State: The process being created.
• Running State: A process is said to be running if it has the CPU, that is, 
process actually using the CPU at that particular instant.
• Blocked (or waiting) State: A process is said to be blocked if it is waiting for 
some event to happen such that as an I/O completion before it can proceed. 
Note that a process is unable to run until some external event happens.
• Ready State: A process is said to be ready if it use a CPU if one were 
available. A ready state process is runable but temporarily stopped running to 
let another process run.
• Terminated state: The process has finished execution.
Schedulers: A process migrates among various scheduling queues throughout its 
lifetime. The OS must select for scheduling purposes, processes from those 
queues in some fashion. The selection process is carried out by the appropriate 
scheduler.
Long Term Scheduler: A long term scheduler or job scheduler selects processes 
from job pool (mass storage device, where processes are kept for later execution) 
and loads them into memory for execution. The long term scheduler controls the 
degree of multiprogramming (the number of processes in memory).
Short Term Scheduler: A short term scheduler or CPU scheduler selects from the 
main memory among the processes that are ready to execute and allocates the 
CPU to one of them.Medium Term Scheduler: The medium term scheduler available 
in all systems which is responsible for the swapping in and out operations which 
means loading the process into, main memory from secondary memory (swap in) 
and take out the process from main memory and store it into the secondary 
memory (swap out).
A sp ects :
L on g Term 
S ch ed u ler
M ed iu m Term 
S ch ed u ler
S h ort Term 
S ch ed u ler
C alled as
It is a j o b s c h e d u le r It is a p ro c e s s 
s w a p p in g
It is a C P U s c h e d u le r
Speed
S p e e d is le s s e r th a n S p e e d is in b e tw e e n S p e e d is fa s te st a m o n g 
sh o rt te rm b o th tw o o th e r s c h e d u le r 
s c h e d u le r s h o rt an d lo n g te rm 
s c h e d u le r
M u lti prog rani ruing
It c o n tro ls th e It re d u c e s th e d e g re e It p ro v id e s le s s e r 
d e g re e o f o f c o n tr o l o v e r d e g re e o f 
m u ltip ro g ra m m in g m u ltip r o g r a m m in g m u ltip ro g ra m m in g
T im e-sh arin g sy stem
It is a lm o s t a b s e n t It is a p a rt o f T im e It is a ls o m in im a l in 
o r m in im a l in tim e s h a r in g s y s te m tim e s h a rin g sy s te m 
s h a rin g sy s te m
P rocesses
It s e le c ts p ro c e s s e s It c a n r e in tro d u c e 
fro m p o o l a n d th e p ro c e s s in to 
lo a d s th e m in to m e m o ry an d 
m e m o ry fo r e x e c u tio n c a n b e 
e x e c u tio n c o n tin u e d
It se le c ts th o s e 
p ro c e s s e s w h ic h are 
r e a d y to e x e c u te
Dispatcher:
• It is the module that gives control of the CPU to the process selected by the 
short-term scheduler.
• Functions of Dispatcher: Switching context, Switching to user mode, and 
Jumping to the proper location in the user program to restart that program.
The fork():
System call fork() is used to create processes. It takes no arguments and returns a 
process ID . The purpose of fork() is to create a new process, which becomes 
the child process of the caller. After a new child process is created, both processes 
will execute the next instruction following the forkQ system call. Therefore, we 
have to distinguish the parent from the child. This can be done by testing the 
returned value of fork():
• If fork() returns a negative value, the creation of a child process was 
unsuccessful.
• fork() returns a zero to the newly created child process.
• fork() returns a positive value, the process ID of the child process, to the 
parent. The returned process ID is of type pid_t defined in sys/types.h. 
Normally, the process ID is an integer. Moreover, a process can use 
function getpid() to retrieve the process ID assigned to this process.
Therefore, after the system call to fork(), a simple test can tell which process is the 
child. Please note that Unix will make an exact copy of the parent's address space 
and give it to the child. Therefore, the parent and child processes 
have separate address spaces.
Example:
Calculate a number of times hello is printed.
#include <stdio.h>
#include <sys/types.h> 
int main()
{
forkQ;
forkQ;
forkQ;
printf("hello\n"); 
return 0;
}
Solutions:
Number of times hello printed is equal to number of processes created. Total 
Number of Processes = 2n where n is the number of fork system calls. So here n =
3, 23 = 8.
Ques: what are threads?
Thread: A thread is a single sequence stream within in a process. Because threads 
have some of the properties of processes, they are sometimes called lightweight 
processes. In a process, threads allow multiple executions of streams. An 
operating system that has thread facility, the basic unit of CPU utilization is a 
thread.
• A thread can be in any of several states (Running, Blocked, Ready or 
Terminated).
• Each thread has its own stack.
• A thread has or consists of a program counter (PC), a register set, and a stack 
space. Threads are not independent of one other like processes as a result 
threads shares with other threads their code section, data section, OS 
resources also known as task, such as open files and signals.
Multithreading: An application typically is implemented as a separate process with 
several threads of control. In some situations, a single application may be required 
to perform several similar tasks, e.g., a web server accepts client request for web 
pages, images, sound and so on.
• Threads share CPU and only one thread active (running) at a time.
• Threads within a process, threads within a process execute sequentially.
• Thread can create children.
• If one thread is blocked, another thread can run.
• Threads are not independent of one another.
• All threads can access every address in the task .
• Threads are design to assist one other.
Multithreading Model: There are two types of threads.
1. User threads
2. Kernel threads
User Threads: They are above the kernel and they are managed without kernel 
support. User-level threads implement in user-level libraries, rather than via 
systems calls, so thread switching does not need to call operating system and to 
cause interrupt to the kernel. In fact, the kernel knows nothing about user-level 
threads and manages them as if they were single-threaded processes. Kernel 
Threads: Kernel threads are supported and managed directly by the operating 
system. Instead of thread table in each process, the kernel has a thread table that 
keeps track of all threads in the system. In addition, the kernel also maintains the 
traditional process table to keep track of processes. Operating Systems kernel 
provides system call to create and manage threads. Kernel level threads are slower, 
inefficient, complex, overhead, and weighter compared to User level threads. There 
are three common ways of establishing relationship between user threads and 
kernel threads
1. Many-to-many model
2. One-to-one model
3. Many-to-one model
• One-to-one model maps each user thread to corresponding kernel threads.
• Many-to-many model multiplexes many user threads to a smaller or equal 
number of kernel threads.
• Many-to-one model maps many user threads to single kernel threads.
• User level threads are threads that are visible to the programmer and 
unknown to the Kernel.
Read More
90 docs

Top Courses for Computer Science Engineering (CSE)

90 docs
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

pdf

,

past year papers

,

Previous Year Questions with Solutions

,

Viva Questions

,

study material

,

Sample Paper

,

Objective type Questions

,

ppt

,

video lectures

,

Semester Notes

,

Important questions

,

Exam

,

Summary

,

MCQs

,

Free

,

mock tests for examination

,

practice quizzes

,

Short Notes: Processes Managements - Process and Threads | Short Notes for Computer Science Engineering - Computer Science Engineering (CSE)

,

Short Notes: Processes Managements - Process and Threads | Short Notes for Computer Science Engineering - Computer Science Engineering (CSE)

,

Extra Questions

,

shortcuts and tricks

,

Short Notes: Processes Managements - Process and Threads | Short Notes for Computer Science Engineering - Computer Science Engineering (CSE)

;