Process Management
Process Management
Process Management
Process Management
Section 3.1 Process
Definition:
A process is basically a program in execution or instance of the program execution. The
execution of a process must progress in a sequential fashion.
Process is not as same as program code but a lot more than it.
A process is an 'active' entity as opposed to program which is considered to be a
'passive' entity.
Attributes held by process include hardware state, memory, CPU etc.
Process States:
When a process executes, it passes through different states. These stages may differ in
different operating systems.
Page 1 of 12
Operating System Handout
In general, a process can have one of the following five states at a time.
Page 2 of 12
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.
Page 3 of 12
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 12
Operating System Handout
Page 5 of 12
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 12
Operating System Handout
Page 7 of 12
Operating System Handout
Page 8 of 12
Operating System Handout
Page 9 of 12
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 10 of 12
Operating System Handout
Page 11 of 12
Operating System Handout
Page 12 of 12