Process in Operating System
Process in Operating System
A program is an inanimate entity; only when a processor “breathes life” into it does it become
the “active” entity.
Process States:
Process Transition:
When a job is admitted to the system, a corresponding process is created and normally
inserted at the back of the ready list.
The process gradually moves to the head of the ready list as the processes before it complete
their turns at using the CPU. When the process reaches the head of the list, and when the
CPU becomes available, the process is given the CPU and is said to make a state transition
from ready state to the running state (Fig. 1).
The assignment of the CPU to the first process on the ready list is called dispatching, and is
performed by a system entity called the dispatcher.
To prevent any one process from monopolizing the system, either accidentally or maliciously,
the operating system sets a hardware interrupting clock (or interval timer) to allow this user
to run for a specific time interval or quantum. If the process does not voluntarily relinquish
the CPU before the time interval expires, the interrupting clock generates an interrupt,
causing the operating system to regain control. The operating system then makes the
previously “running” process “ready”, and makes the first process on the ready list running.
1
Operating System
If a running process initiates an input/output operation before its quantum expires, the
running process voluntarily relinquishes the CPU (i.e., the process blocks itself pending the
completion of the input/output operation).
The only other allowable state transition in our three-state model occurs when an input/
output operation (or some other event the process is waiting for) completes. The process
makes the transition from the blocked state to the ready state.
Note that only state transition initiated by user process itself is block – the other three
transitions are initiated by entities external to the process.
The PCB is a data structure containing certain important information about the process
including:
The PCB is a central store of information that allows the operating system to locate all key
information about a process. When the operating system switches the attention of the CPU
among the various active processes, it uses the save areas in the PCB to hold the information
it needs to restart each process when the process next gets the CPU.
Operations on Processes:
Systems that manage processes must be able to perform certain operations on and with
processes. These include create a process, destroy a process , suspend a process, resume a
process, change priority of a process, block a process, wakeup a process, dispatch a
process, enable a process to communicate with another process (called interprocess
communication)
Creating a process involves many operations including, name the process, insert it in the
system's known processes list (or process table), determine the process's initial priority, create
the process control block, allocate the process's initial resources
A process may spawn a new process. If it does, the creating process is called the parent
process and the created process is called the child process. Only one parent is needed to
create a child. Such creation yields a hierarchical process structure.
2
Operating System
Destroying a process involves obliterating it from the system. Its resources are returned to the
system, it is purged from any system lists or tables, and its process control block is erased.
When a process is suspended, a part of the process or the entire process is moved from main
memory to disk. This is also called Swapping.
Thus, Swapping is an I/O operation but disk I/O is faster than peripheral I/O.
Swapping - the operating system needs to release sufficient main memory to bring in
a process that is ready to execute.
3
Operating System
Other OS reason - the operating system may suspend a background or utility process
or a process that is suspected of causing a problem.
Interactive user request - a user may wish to suspend a background or utility process
or a process that is suspected of causing a problem.
Timing - a process may be executed periodically and may be suspended while
waiting for the next time interval.
Parent process request - a parent process may wish to suspend execution of a
descendent to examine or modify the suspended process, or to coordinate the activity
of various decedents.
Interrupt Processing:
On a computer system, an interrupt is an event that alters the sequence in which a processor
executes instructions. It is generated by the hardware of the computer system. When an
interrupt occurs
The operating system gains control (i.e., the hardware passes control to the operating
system).
The operating system saves the state of the interrupted process. In many systems this
information is stored in the interrupted process's process control block.
The operating system analyzes the interrupt and passes control to the appropriate
routine to handle the interrupt; on many of today's systems this is handled
automatically by the hardware.
The interrupt handler routine processes the interrupt.
The state of the interrupted process (or some other "next process") is restored.
The interrupted process (or some other "next process") executes.
An interrupt may be specifically initiated by a running process (in which case it is often
called a trap and said to be synchronous with the operation of the process), or it may be
caused by some event that may or may not be related to the running process (in which case it
is said to be asynchronous with the operation of the process).
Advantage of Interrupt: A key advantage to the interrupt concept is that it provides a low-
overhead means of gaining the attention of the CPU. This eliminates the need for the CPU to
remain busy polling to see if devices require its attention.
4
Operating System
4. Restart interrupts: These occur when the operator presses the console's restart button,
or when a restart SIGP (signal processor) instruction arrives from another processor
on a multiprocessor system.
5. Program check interrupts: These are caused by a wide range of problems that may
occur as a program's machine language instructions are executed. These problems
include division by zero, arithmetic overflow or underflow, data (being operated
upon) is in the wrong format, attempt to execute an invalid operation code, attempt to
reference a memory location beyond the limits of real memory etc.
6. Machine Check Interrupt: This interrupt takes place due to a malfunctioning
hardware.
Context Switching
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.
This mechanism is used in handling interrupts and resuming the general processes after the
interrupt is handled.
All of the operations involving processes are controlled by a portion of the operating
system variously called its nucleus, core, or kernel.
The nucleus normally represents only a small portion of the code of what is
commonly thought to be the entire operating system, but it is among the most
intensively used code. For this reason, the nucleus ordinarily remains in primary
storage while other portions of the operating system are shuttled to and from
secondary storage as needed.
One of the most important functions included in the nucleus is interrupt processing.
In large, multiuser systems, a constant blizzard of interrupts is directed at the
processor. Rapid response to these interrupts is essential to keeping the resources of
the system well utilized, and to providing acceptable response times to interactive
users.
The nucleus disables interrupts while it is responding to an interrupt; interrupts are
again enabled after the processing of an interrupt is complete.