Unit 2
Unit 2
PROCESS MANAGEMENT
Process:
A process is basically a program in execution. The execution of a process must
progress in a sequential fashion.
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 1 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 2 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 3 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
The PCB is maintained for a process throughout its lifetime, and is deleted once
the process terminates.
Process Scheduling:
Definition
The process scheduling is the activity of the process manager that handles the
removal of the running process from the CPU and the selection of another
process on the basis of a particular strategy.
Process scheduling is an essential part of a Multiprogramming operating
systems. Such operating systems allow more than one process to be loaded into
the executable memory at a time and the loaded process shares the CPU using
time multiplexing.
Process Scheduling Queues
The OS maintains all PCBs in Process Scheduling Queues. The OS maintains a
separate queue for each of the process states and PCBs of all processes in the
same execution state are placed in the same queue. When the state of a process
is changed, its PCB is unlinked from its current queue and moved to its new
state queue.
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 4 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
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. A new process is always put in this
queue.
Device queues - The processes which are blocked due to unavailability of an
I/O device constitute this queue.
The OS can use different policies to manage each queue (FIFO, Round Robin,
Priority, etc.). The OS scheduler determines how to move processes between the
ready and run queues which can only have one entry per processor core on the
system; in the above diagram, it has been merged with the CPU.
Schedulers:
Schedulers are special system software which handle process scheduling in
various ways. Their main task is to select the jobs to be submitted into the
system and to decide which process to run. Schedulers are of three types -
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 5 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 6 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
Context Switch:
A context switch is the mechanism to store and restore the state or context of a
CPU in Process Control block so that a process execution can be resumed from
the same point at a later time. Using this technique, a context switcher enables
multiple processes to share a single CPU. Context switching is an essential part
of a multitasking operating system features.
When the scheduler switches the CPU from executing one process to execute
another, the state from the current running process is stored into the process
control block. After this, the state for the process to run next is loaded from its
own PCB and used to set the PC, registers, etc. At that point, the second process
can start executing.
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 7 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
Context switches are computationally intensive since register and memory state
must be saved and restored. To avoid the amount of context switching time,
some hardware systems employ two or more sets of processor registers. When
the process is switched, the following information is stored for later use.
• Program Counter
• Scheduling information
• Base and limit register value
• Currently used register
• Changed State
• I/O State information
• Accounting information
Multi-Threading:
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.
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. 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.
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 8 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 9 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
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.
Types of Thread:
Threads are implemented in following two ways
ADVANTAGES
DISADVANTAGES
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 10 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
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
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 provides 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
The following diagram shows the many-to-many threading model where 6 user
level threads are multiplexing with 6 kernel level threads. In this model,
developers can create as many user threads as necessary and the corresponding
Kernel threads can run in parallel on a multiprocessor machine. This model
provides the best accuracy on concurrency and when a thread performs a
blocking system call, the kernel can schedule another thread for execution.
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 11 of 12
OPERATING SYSTEM BCA IIISEM (UNIT 2)
If the user-level thread libraries are implemented in the operating system in such
a way that the system does not support them, then the Kernel threads use the
many-to-one relationship modes.
From the Desk of Mr. Manjunatha Balluli, S.M.D College, BALLARI. Page 12 of 12