Process Management
Process Management
Process States:
When a process executes, it passes through different states. These stages may differ in
different operating systems.
Page 1 of 11
Operating System Handout
In general, a process can have one of the following five states at a time.
Page 2 of 11
Operating System Handout
The architecture of a PCB is completely dependent on Operating System and may contain
different information in different operating systems. Here is a simplified diagram of a PCB −
The PCB is maintained for a process throughout its lifetime, and is deleted once the process
terminates.
3.2 Proc
ess
Schedulin
g
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.
Page 3 of 11
Operating System Handout
In the first two cases, the process eventually switches from the waiting state to the ready
state, and is then put back in the ready queue. A process continues this cycle until it
terminates, at which time it is removed from all queues and has its PCB and resources
deallocated.
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
Long Term Scheduler
• It is also called a job scheduler.
• A long-term scheduler determines which programs are admitted to the system for
processing.
• It selects processes from the queue and loads them into memory for execution.
• Process loads into the memory for CPU scheduling.
• The primary objective of the job scheduler is to provide a balanced mix of jobs, such
as I/O bound and processor bound.
Page 4 of 11
Operating System Handout
Page 5 of 11
Operating System Handout
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.
• 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
Page 6 of 11
Operating System Handout
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.
Page 7 of 11
Operating System Handout
Page 8 of 11
Operating System Handout
Advantages
• Thread switching does not require Kernel mode privileges.
• User level thread can run on any operating system.
• Scheduling can be application specific in the user level thread.
• User level threads are fast to create and manage.
Disadvantages
• In a typical operating system, most system calls are blocking.
• Multithreaded application cannot take advantage of multiprocessing.
Kernel Level Threads
In this case, 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. All of the threads
within an application are supported within a single process.
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.
• Kernel routines themselves can be multithreaded.
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
• Many to many relationship.
• Many to one relationship.
• One to one relationship.
Many to Many Model
• The many-to-many model multiplexes any number of user threads onto an equal or
smaller number of kernel threads.
• 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.
Page 9 of 11
Operating System Handout
Page 10 of 11
Operating System Handout
Page 11 of 11