Академический Документы
Профессиональный Документы
Культура Документы
Priority Scheduling
P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13
The processer should know in advance how much time process will take.
P0 3-0=3
P1 0-0=0
P2 16 - 2 = 14
P3 8-3=5
Processes with same priority are executed on first come first served basis.
P0 9-0=9
P1 6-1=5
P2 14 - 2 = 12
P3 0-0=0
It is often used in batch environments where short jobs need to give preference.
Once a process is executed for a given time period, it is preempted and other
process executes for a given time period.
P0 (0 - 0) + (12 - 3) = 9
P1 (3 - 1) = 2
P3 (9 - 3) + (17 - 12) = 11
For example, CPU-bound jobs can be scheduled in one queue and all I/O-
bound jobs in another queue. The Process Scheduler then alternately selects
jobs from each queue and assigns them to the CPU based on the algorithm
assigned to the queue.
……
A process is an active program i.e. a program that is under execution. It is more than the program
code as it includes the program counter, process stack, registers, program code etc. Compared to
this, the program code is only the text section.
A thread is a lightweight process that can be managed independently by a scheduler. It improves the
application performance using parallelism. A thread shares information like data segment, code
segment, files etc. with its peer threads while it contains its own registers, stack, counter etc.
The major differences between a process and a thread are given as follows:
Comparison
Process Thread
Basis
A thread is a lightweight process that
A process is a program under
Definition can be managed independently by a
execution i.e an active program.
scheduler.
Processes require more time for Threads require less time for context
Context switching
context switching as they are more switching as they are lighter than
time
heavy. processes.
Processes are totally independent A thread may share some memory with
Memory Sharing
and don’t share memory. its peer threads.
Communication between processes Communication between threads
Communication requires more time than between requires less time than between
threads. processes .
If a process gets blocked, remaining If a user level thread gets blocked, all
Blocked
processes can continue execution. of its peer threads also get blocked.
Resource Processes require more resources Threads generally need less resources
Consumption than threads. than processes.
Individual processes are Threads are parts of a process and so
Dependency
independent of each other. are dependent.
A thread shares the data segment,
Data and Code Processes have independent data
code segment, files etc. with its peer
sharing and code segments.
threads.
All the different processes are All user level peer threads are treated
Treatment by OS treated separately by the operating as a single task by the operating
system. system.
Processes require more time for
Time for creation Threads require less time for creation.
creation.
Time for Processes require more time for Threads require less time for
termination termination. termination.
Operating System - Processes
Process
A process is basically a program in execution. The execution of a process
must progress in a sequential fashion.
A process is defined as an entity which represents the basic unit of work to be
implemented in the system.
To put it in simple terms, we write our computer programs in a text file and
when we execute this program, it becomes a process which performs all the
tasks mentioned in the program.
When a program is loaded into the memory and it becomes a process, it can
be divided into four sections ─ stack, heap, text and data. The following image
shows a simplified layout of a process inside main memory −
1 Stack
The process Stack contains the temporary data such as method/function
parameters, return address and local variables.
2 Heap
3 Text
4 Data
Program
A program is a piece of code which may be a single line or millions of lines.
A computer program is usually written by a computer programmer in a
programming language. For example, here is a simple program written in C
programming language −
#include <stdio.h>
int main() {
return 0;
In general, a process can have one of the following five states at a time.
1 Start
2 Ready
3 Running
Once the process has been assigned to a processor by the OS scheduler, the
process state is set to running and the processor executes its instructions.
4 Waiting
Process moves into the waiting state if it needs to wait for a resource, such
as waiting for user input, or waiting for a file to become available.
5 Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating
system, it is moved to the terminated state where it waits to be removed
from main memory.
1 Process State
The current state of the process i.e., whether it is ready, running, waiting,
or whatever.
2 Process privileges
3 Process ID
4 Pointer
A pointer to parent process.
5 Program Counter
6 CPU registers
Various CPU registers where process need to be stored for execution for
running state.
This includes the information of page table, memory limits, Segment table
depending on memory used by the operating system.
9 Accounting information
This includes the amount of CPU used for process execution, time limits,
execution ID etc.
10 IO status information
What is 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.
Each thread belongs to exactly one process and no thread can exist outside
a process. Each thread represents a separate flow of control. Threads have
been successfully used in implementing network servers and web server.
They also 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.
Difference between Process and Thread
S.N. Process Thread
Advantages of Thread
Threads minimize the context switching time.
Efficient communication.
Types of Thread
Threads are implemented in following two ways −
Disadvantages
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.
Advantages
Kernel can simultaneously schedule multiple threads from the same process on
multiple processes.
If one thread in a process is blocked, the Kernel can schedule another thread of
the same process.
Disadvantages
Kernel threads are generally slower to create and manage than the user threads.
Transfer of control from one thread to another within the same process requires
a mode switch to the Kernel.
Multithreading Models
Some operating system provide a combined user level thread and Kernel level
thread facility. Solaris is a good example of this combined approach. In a
combined system, multiple threads within the same application can run in
parallel on multiple processors and a blocking system call need not block the
entire process. Multithreading models are three types